如何设置在运行时的端点

编程入门 行业动态 更新时间:2024-10-24 06:31:10
本文介绍了如何设置在运行时的端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经根据本教程

方法我用它来测试连接到服务器(在客户端应用程序):

Method I use to test connection to server (in client app):

public class PBMBService : IService { private void btnPing_Click(object sender, EventArgs e) { ServiceClient service = new ServiceClient(); tbInfo.Text = service.Ping().Replace("\n", "\r\n"); service.Close(); } //other methods }

服务的主要功能:

class Program { static void Main(string[] args) { Uri baseAddress = new Uri("localhost:8000/PBMB"); ServiceHost selfHost = new ServiceHost(typeof(PBMBService), baseAddress); try { selfHost.AddServiceEndpoint( typeof(IService), new WSHttpBinding(), "PBMBService"); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; selfHost.Description.Behaviors.Add(smb); selfHost.Open(); Console.WriteLine("Serwis gotowy."); Console.WriteLine("Naciśnij <ENTER> aby zamknąć serwis."); Console.WriteLine(); Console.ReadLine(); selfHost.Close(); } catch (CommunicationException ce) { Console.WriteLine("Nastąpił wyjątek: {0}", ce.Message); selfHost.Abort(); } } }

在的app.config 我有:

<client> <endpoint address="localhost:8000/PBMB/PBMBService" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService" contract="IService" name="WSHttpBinding_IService"> <identity> <userPrincipalName value="PPC\Pawel" /> </identity> </endpoint> </client>

我可以从这里更改IP。但是,我怎么能在运行时改变它(即从文件中读取地址/ IP)?

I can change IP from here. But how can I change it during runtime (i.e. read address/IP from file)?

推荐答案

您可以替换后的服务端点您创建的客户端类:

You can replace the service endpoint after you created your client class:

public class PBMBService : IService { private void btnPing_Click(object sender, EventArgs e) { ServiceClient service = new ServiceClient(); service.Endpoint.Address = new EndpointAddress("the.new.address/to/the/service"); tbInfo.Text = service.Ping().Replace("\n", "\r\n"); service.Close(); } }

更多推荐

如何设置在运行时的端点

本文发布于:2023-06-10 22:52:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/620794.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何设置

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!