gpt4 book ai didi

wcf - 如何更改 WCF 服务端点?

转载 作者:行者123 更新时间:2023-12-04 19:38:01 25 4
gpt4 key购买 nike

我拥有三个以上的网络服务,其中一个是主站点,其他是客户站点。

在我的用户界面中有一个文本框可用,在该文本框中我需要提供目标端点地址从那个文本框值我需要调用客户服务。

例如:

Client1 端点服务名称:

                 http://localhost:1524/WebServiceService.svc" 

Client2 端点服务名称:

通过

拉贾戈帕克

                 http://localhost:8085/WebServiceService.svc" 

如果我在文本框中输入 "localhost:1524" Client1 服务将调用,如果我在文本框中输入 "localhost:8085",Client2 服务将调用,

最佳答案

您是否在 IIS 中托管 WCF 服务?在这种情况下,您的服务地址由 IIS 配置和服务的 *.svc 文件所在的虚拟目录决定。

所以要在服务器上改变一些东西,你需要检查和修改IIS配置。

要在客户端进行更改,有一个 web.config(用于 ASP.NET 网络)或一个 (applicationName).exe.config,其中应包含您的端点定义 - 更改那里的端点地址:

<client> 
<endpoint name="YourEndpointName"
address="http://localhost:8085/WebServiceService.svc"
binding="......." bindingConfiguration="............."
contract="..................." />
</client>

您需要在address=中指定完整的目标网络服务地址。你的 <endpoint> 的属性配置元素。

您可以为同一服务定义多个端点,并在实例化客户端代理时选择使用哪个端点:

MyServiceProxy client = new MyServiceProxy("name of endpoint configuration");

有了这个,您可以轻松地在多个端点定义之间切换。

更新:如果您想通过代码以编程方式设置您的客户端地址,您需要在创建客户端代理时执行以下操作:

// create custom endpoint address in code - based on input in the textbox
EndpointAddress epa = new EndpointAddress(new Uri(textbox.Text));

// instantiate your cilent proxy using that custom endpoint address
// instead of what is defined in the config file
MyServiceProxy client = new MyServiceProxy("name of endpoint configuration", epa);

关于wcf - 如何更改 WCF 服务端点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2234669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com