【问题标题】:WCF endpoints are driving me insaneWCF 端点让我发疯
【发布时间】:2011-04-28 20:05:14
【问题描述】:

也许我只是不明白,但我有一个部署到 IIS 6 机器的服务。那台机器有一个 LAN 地址和一个公共互联网地址。

我到底应该怎样才能发布这个服务并且两者都可以访问?

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

<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>

这对我来说肯定不合适。

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

【问题讨论】:

    标签: c# .net-3.5 wcf


    【解决方案1】:

    这是我的工作:

    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();
    

    等等

    【讨论】:

    • 有一天,我可能会向您介绍小奥塔维奥。谢谢。
    • @SnOrfus - 很高兴能提供帮助并感谢您的荣幸 :-)
    【解决方案2】:

    您是否真的将字符串“地址 1”和“地址 2”放入配置文件中?

    框架总是解析地址以了解要使用的传输方式。例如“http://myurl”将使用http,“net.pipe://localhost/MyNamedPipeExample”将使用IPC。

    错误是因为字符串“地址1”中没有前缀。

    我相信这会奏效,无需对地址进行硬编码:

    <endpoint 
        address="http://serverName/ServiceName/Service.svc" 
        binding="wsHttpBinding" 
        bindingConfiguration="DefaultBindingConfiguration" 
        name="RemoteEndpoint" />
    
    <endpoint
        address="http://www.companyName.com/ServiceName/Service.svc" 
        binding="wsHttpBinding" 
        bindingConfiguration="DefaultBindingConfiguration" 
        name="LocalEndpoint" />
    

    【讨论】:

    【解决方案3】:

    万一它有用,我在更新版本的 IIS 中遇到了同样的错误。在这种情况下,一种可能性是仅指定一个端点并将地址保留为空字符串。然后将以下内容添加到服务的 web.config 的 system.serviceModel 部分:

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    

    我在 IE 中浏览到我的第二个地址时遇到协议绑定错误,所以我想解决这个问题,而不是仅仅在客户端使用解决方法。

    更多关于multipleSiteBindingsEnabled设置的信息在这里:https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/supporting-multiple-iis-site-bindings

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-30
      • 2012-11-02
      • 2020-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多