【发布时间】:2011-04-28 20:05:14
【问题描述】:
也许我只是不明白,但我有一个部署到 IIS 6 机器的服务。那台机器有一个 LAN 地址和一个公共互联网地址。
我到底应该怎样才能发布这个服务并且两者都可以访问?
- 地址1:http://serverName/ServiceName/Service.svc
- 地址2:http://www.companyName.com/ServiceName/Service.svc
起初我想:没什么大不了的,两个端点。所以我有
<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");
}
没有骰子。无法添加服务引用。
没有与给定地址“地址 1”匹配的协议绑定。协议绑定在 IIS 或 WAS 配置中的站点级别进行配置。
然后我想:也许主机标签和它的 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 时...
在 ServiceModel 客户端配置部分找不到名为“MyEndpointName”和合同 MyService.IService 的端点元素。
这将我带到 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>
这对我来说肯定不合适。
我的下一个想法不是一个健康的想法。请帮忙。
【问题讨论】: