【问题标题】:ClientBaseAddress doesn't seem accessibleClientBaseAddress 似乎无法访问
【发布时间】:2013-01-03 21:10:46
【问题描述】:

我正在使用 wsDualHttpBinding,服务器是自托管的。 我遇到了一个问题,在我看来,我的客户端的 ClientBaseAddress 无法访问。我不知道如何解决这个问题。

这是我的服务配置:

<system.serviceModel>
<services>
  <service name="GuiEndpoint.GuiService">
    <endpoint address="" 
              binding="wsDualHttpBinding"
              bindingConfiguration="GuiEndpoint" 
              name="dualHttpBinding" 
              contract="Common.IGuiService">
      <!--<identity>
        <dns value="localhost"/>
      </identity>-->
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange"/>
    <host>
      <baseAddresses>
        <add baseAddress="http://192.168.1.199:8733/Design_Time_Addresses/GuiEndpoint/IGuiService/"/>
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="True"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <wsDualHttpBinding>
    <binding name="GuiEndpoint">
      <security mode="None">
        <message clientCredentialType="None"/>
      </security>
    </binding>
  </wsDualHttpBinding>
</bindings>
<diagnostics>
  <messageLogging logEntireMessage="true"
                  maxMessagesToLog="300"
                  logMessagesAtServiceLevel="true"
                  logMalformedMessages="true"
                  logMessagesAtTransportLevel="true" />
</diagnostics>

在我的客户端上,我使用此代码以编程方式连接:

WSDualHttpBinding binding = new WSDualHttpBinding();

binding.Security.Mode = WSDualHttpSecurityMode.None;
binding.Security.Message.ClientCredentialType = MessageCredentialType.None;
binding.ClientBaseAddress = new Uri("192.168.1.189:8080/TempUri");

EndpointAddress endpoint = new EndpointAddress(Helper.CreateUri(client.Connection.ServerAddress));

context = new InstanceContext(this);

serviceClient = new GuiServiceClient(context, binding, endpoint);
serviceClient.InnerDuplexChannel.Faulted += InnerChannelOnFaulted;

try
{
    if (serviceClient.Subscribe())
    {
        startKeepAliveTimer();
    }
}
catch (EndpointNotFoundException)
{
    this.Error("Couldn't Connect!");
}

现在,使用 Fidler 我可以看到消息来回传递。

服务器:

客户:

如您所见,客户端可以与服务器通信,但服务器似乎无法与客户端通信。

我也在客户端注册了命名空间:

客户端端口也可以访问:

Starting Nmap 6.25 ( http://nmap.org ) at 2013-01-03 14:05 Mountain Standard Time

Nmap scan report for 192.168.1.189

Host is up (0.10s latency).

PORT     STATE SERVICE

8080/tcp open  http-proxy

MAC Address: xx:0B:A9:57:xx:xx (Intel Corporate)

Nmap done: 1 IP address (1 host up) scanned in 13.42 seconds

这里的任何帮助都会很棒!

【问题讨论】:

  • 另外,两台机器上的 Windows 防火墙都已完全关闭。

标签: wcf .net-4.5 endpoint wsdualhttpbinding


【解决方案1】:

微软未能在任何文档中提供的是:

您在 ClientBaseAddress 中指定的 IP 地址必须可解析为主机名。换句话说,如果服务器无法通过其 HOST NAME ping 客户端,那么您将永远无法建立连接。

正如您所发现的那样,它根本行不通!

尝试将 192.168.1.189 替换为客户端 PC 的主机名,如下所示:

 http://ClientHostName:8080/TempURI

另外作为提示,如果您不想注册任何端口,只需使用地址

http://MyClientHostName/Temporary_Listen_Addresses/TempUri

因为你可以注册任何以

开头的url
http://+80/Temporary_Listen_Addresses/

【讨论】:

    猜你喜欢
    • 2018-09-03
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多