1

我有一个 wcf 服务并将其安装为 Windows 服务。我可以从 192.168.2.6 机器访问此服务:

"net.tcp://192.168.2.5:2025/Services/mex".

我想使用静态 ip 和端口从另一台计算机访问此服务。

怎样才能访问此服务?

我试图连接 net.tcp://staticIp:port/Services/mex 并出现错误:

Metadata contains a reference that cannot be resolved: 'net.tcp://[staticIP]:[port]/Services/mex'.If the service is defined in the current solution, try building the solution and adding the service reference again.

(我将我的 [port] 导航到内部端口 2025)

我的配置:

<system.serviceModel>
<diagnostics>
  <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<bindings>
  <netTcpBinding>
    <binding name="NetTcpBinding_IServices" />
  </netTcpBinding>
</bindings>
<client>
  <endpoint address="net.tcp://192.168.2.5:2025/Services" binding="netTcpBinding"
    bindingConfiguration="NetTcpBinding_IServices" contract="myServices.IServices"
    name="NetTcpBinding_IServices">
    <!--<identity>
      <dns value="localhost" />
    </identity>-->
  </endpoint>
</client>
<services>
  <service name="F8ShadowWcfLib.Services">
    <endpoint address="" binding="netTcpBinding" bindingConfiguration=""
      contract="F8ShadowWcfLib.IServices">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
      contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://192.168.2.5:2025/Services" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="false"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

编辑1:

我从配置中删除标签并在运行时添加它。

myService.ServicesClient myServ = new myService.ServicesClient();
            EndpointAddress myEndpointAdd = new EndpointAddress(new Uri("net.tcp://[staticIP]:[port]/Services") ,
                                                EndpointIdentity.CreateDnsIdentity("net.tcp://f8srv.f8.com.tr:2299/Services"));

myServ.Endpoint.Address = myEndpointAdd;

我得到了不同的错误:服务器拒绝了客户端凭据。

4

2 回答 2

1

问题可能与这部分有关:

<identity>
    <dns value="localhost" />
</identity>

这项工作在本地工作,因为 localhost 在本地有意义,但在网络上却没有。

您可以通过多种方式验证此身份,例如指定运行服务的用户的 UPN(用户主体名称)或运行服务的服务器的 SPN(服务器主体名称)(尽管为此您将拥有注册 SPN)。

这篇文章应该稍微解释一下:

http://msdn.microsoft.com/en-us/library/ms733130.aspx

于 2013-09-12T16:07:45.413 回答
0

要允许单独的连接设置 AddressFilterMode : Any 并设置您的身份,包括服务端和客户端。

这篇关于身份设置的文章:

http://msdn.microsoft.com/en-us/library/ms733130.aspx

 [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
   public class Services : IServices
   {
        .
        .
        .
   }
于 2013-09-14T14:08:19.177 回答