我有一个 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;
我得到了不同的错误:服务器拒绝了客户端凭据。