C# WCF动态绑定-如何指定端点?
我正在尝试使用代码而不是app.config绑定我的WCF客户端,因为我需要为不同的部署更改主机IP地址 这是我的app.config:C# WCF动态绑定-如何指定端点?,c#,.net,wcf,C#,.net,Wcf,我正在尝试使用代码而不是app.config绑定我的WCF客户端,因为我需要为不同的部署更改主机IP地址 这是我的app.config: <?xml version="1.0" encoding="utf-8"?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/> </s
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ICX" maxReceivedMessageSize="1073741824" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://127.0.0.1/CX/CX.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICX" contract="CXService.ICX" name="WSHttpBinding_ICX">
<identity>
<servicePrincipalName value="host/SilverStar" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
代码的最后一行未编译为。EndPoint是只读属性
请帮助。试试这个:
Globals.CXClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("your url here");
我就是这样做的
Globals.CXClient.Endpoint.Contract = new ContractDescription("CXService.ICX");
Globals.CXClient.Endpoint.Binding = binding1;
Globals.CXClient.Endpoint.Address = addr;
然而,我遇到了另一个问题。我试图更换零件:
<identity>
<servicePrincipalName value="host/SilverStar" />
</identity>
由于addr.Identity是只读的,因此此文件再次无法编译
我也试过:
EndpointAddress addr = new EndpointAddress(new Uri("http://127.0.0.1/CX/CX.svc"), new SpnEndpointIdentity("host/SilverStar"), ???);
但最后一个参数是AddressHeaderCollection,我不知道应该在其中放置什么
请再帮忙。谢谢。看看这个网站。
addr.Identity = new SpnEndpointIdentity("host/SilverStar");
EndpointAddress addr = new EndpointAddress(new Uri("http://127.0.0.1/CX/CX.svc"), new SpnEndpointIdentity("host/SilverStar"), ???);