C# 更改WCF终结点

C# 更改WCF终结点,c#,wcf,wcf-binding,spring.net,wcf-endpoint,C#,Wcf,Wcf Binding,Spring.net,Wcf Endpoint,我从spring.net示例中显示的初始示例中获得了以下配置 <wcf:channelFactory id="serverAppHost" channelType="Contract.IHost, WcfService.Contract" endpointConfigurationName="serverAppHostEndpoint" /> <client> <endpoint name="serverAppHostEndpoint" address="

我从spring.net示例中显示的初始示例中获得了以下配置

<wcf:channelFactory id="serverAppHost"
channelType="Contract.IHost, WcfService.Contract"
endpointConfigurationName="serverAppHostEndpoint" />

<client>
    <endpoint name="serverAppHostEndpoint" address="http://xxxxx:yyyyy/program/service/host" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding1" contract="Contract.IHost"/> 
</client>
如果上面的端点具有正确的IP地址和端口号,所有这些都可以正常工作


我正在寻找一种在代码中编辑端点的方法,以使用启动时不知道的ip地址和端口号。有没有办法做到这一点

我解决了一个类似的问题。基本上,一旦应用程序运行,通道工厂就不是很灵活了。您最好使用服务代理并像这样动态设置端点

var client = new SampleClient();
client.Endpoint.Address = new EndpointAddress(url);
client.Open();
responseMessage = client.ServiceMethod(requestMessage);
SampleClient是VisualStudio为您生成的服务代理。您需要一个WSDL来生成它。在Web.config中仍然需要一个虚拟客户机/端点标记,但在加载动态URL时,该标记将被覆盖


如果你需要更多的细节,请告诉我。我可以指导您完成具体的实现。

这是标准的wcf,我需要通过应用程序上下文引用客户端端点。好的,很抱歉,我无法在这方面帮助您。我们只是使用spring来提供wcf服务。我们将客户端封装在一个网关中,该网关被注入到任何需要它们的地方。
var client = new SampleClient();
client.Endpoint.Address = new EndpointAddress(url);
client.Open();
responseMessage = client.ServiceMethod(requestMessage);