也许我只是不明白,但我有一个部署到 IIS 6 机器上的服务。该机器有一个 LAN 地址和一个公共(public)互联网地址。
我究竟应该如何才能发布这项服务,同时兼具两者的可访问性?
- 地址 1:http://serverName/ServiceName/Service.svc
- 地址 2:http://www.companyName.com/ServiceName/Service.svc
起初我想:没什么大不了的,2个端点。所以我有
<endpoint
address="Address 1"
binding="wsHttpBinding"
bindingConfiguration="DefaultBindingConfiguration"
name="RemoteEndpoint" />
<endpoint
address="Address 2"
binding="wsHttpBinding"
bindingConfiguration="DefaultBindingConfiguration"
name="LocalEndpoint" />
客户端代码如下所示:
public void createServiceProxy()
{
if (Util.IsOperatingLocally())
this.proxy = new ProxyClient("LocalEndpoint");
else
this.proxy = new ProxyClient("RemoteEndpoint");
}
没有骰子。无法添加服务引用。
No protocol binding matches the given address 'Address 1'. Protocol bindings are configured at the Site level in IIS or WAS configuration.
然后我想:也许主机标签和它的 dns 标签会有帮助。不,那是为了身份验证。
然后我想:我将使用 net.tcp 作为本地端点。糟糕...IIS 6 不支持 net.tcp。
然后我想:我知道,ProxyClient 构造函数将 remoteAddress 字符串作为其第二个参数。现在它看起来像:
<endpoint
address=""
binding="wsHttpBinding"
bindingConfiguration="DefaultBindingConfiguration"
name="MyEndpointName" />
public void createServiceProxy()
{
if (Util.IsOperatingLocally())
this.proxy = new ProxyClient("MyEndpointName", "Address 1");
else
this.proxy = new ProxyClient("MyEndpointName", "Address 2");
}
显然不是。尝试实例化 ProxyClient 时...
Could not find endpoint element with name 'MyEndpointName' and contract MyService.IService' in the ServiceModel client configuration section.
这将我引向 app.config,其生成的客户端部分如下所示:
<client>
<endpoint address="http://localhost:3471/Service.svc" binding="customBinding"
bindingConfiguration="MyEndpointName" contract="MyService.IService"
name="MyEndpointName">
<identity>
<userPrincipalName value="DevMachine\UserNa,e" />
</identity>
</endpoint>
</client>
我觉得这肯定不对。
我的下一个想法是不健康的。请帮忙。
最佳答案
这是我的做法:
PortClient client = new PortClient(); // from the service reference
EndpointAddress endpointAddress;
if (local)
endpointAddress = new EndpointAddress("http://local/Service.svc");
else
endpointAddress = new EndpointAddress("http://remote/Service.svc");
client.ChannelFactory.CreateChannel(endpointAddress);
client.RemoteMethod();
等等
关于c# - WCF 端点让我抓狂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3991511/