asp.net - 如何从另一台计算机访问wcf服务?

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

编辑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;

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

最佳答案

问题可能与这部分有关:

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

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

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

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

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

关于asp.net - 如何从另一台计算机访问wcf服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18765713/

相关文章:

http - 为什么用户代理在服务器重置 TCP 后重新提交请求?

asp.net - IIS 8 : Custom app pool ID: Value does not fall within the expected range

asp.net - ASP.NET 如何解析页面?

.net - 远程使用 net.pipe 绑定(bind)的 WCF 问题

c# - 使用企业 CA 的 WCF SSL 证书

c# - System.Timer 在单独的线程中流逝并保持线程限制

tcp - 如何在 tcp 连接中使用 LoopBack

javascript - 在 $(document).ready() 函数中设置的 jQuery 值

c# - 如何使用数据库检索日期设置raddatepicker日期

c++ - 在 MFC 应用程序中监听 UDP 或切换到 TCP