如何从另一台计算机访问wcf服务?

时间:2013-09-12 13:29:36

标签: asp.net wcf tcp wcf-data-services

我有一个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.

(我将[端口]导航到端口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>

EDIT1:

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

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;

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

2 个答案:

答案 0 :(得分:1)

问题可能与此部分有关:

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

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

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

本文应该解释一下:

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

答案 1 :(得分:0)

允许单独连接设置AddressFilterMode:Any 并将您的身份设置为服务和客户端。

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

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

 [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
   public class Services : IServices
   {
        .
        .
        .
   }