我有一个 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)。
这篇文章应该稍微解释一下:
关于asp.net - 如何从另一台计算机访问wcf服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18765713/