WCF端点使我发疯

Ste*_*ers 5 c# wcf .net-3.5

也许我只是没有得到它,但是我有一项服务已部署到IIS 6计算机上。该机器具有一个LAN地址和一个公共Internet地址。

我到底应该如何发布可以访问的服务?

起初我想:没什么大不了的,两个端点。所以我有

<endpoint 
    address="Address 1" 
    binding="wsHttpBinding" 
    bindingConfiguration="DefaultBindingConfiguration" 
    name="RemoteEndpoint" />

<endpoint
    address="Address 2" 
    binding="wsHttpBinding" 
    bindingConfiguration="DefaultBindingConfiguration" 
    name="LocalEndpoint" />
Run Code Online (Sandbox Code Playgroud)

客户端代码如下所示:

public void createServiceProxy()
{
    if (Util.IsOperatingLocally())
        this.proxy = new ProxyClient("LocalEndpoint");
    else
        this.proxy = new ProxyClient("RemoteEndpoint");
}
Run Code Online (Sandbox Code Playgroud)

没有骰子。无法添加服务参考。

没有协议绑定与给定的地址“地址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");
}
Run Code Online (Sandbox Code Playgroud)

显然不是。尝试实例化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>
Run Code Online (Sandbox Code Playgroud)

哪个肯定对我不正确。

我的下一个想法是不健康的。请帮忙。

Otá*_*cio 4

这就是我所做的:

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();
Run Code Online (Sandbox Code Playgroud)

ETC。