我没有足够的WCF及其配置经验,我不知道如何解决这个问题。所以我很抱歉这个,可能是愚蠢的问题。
我的虚拟机具有托管WCF的Windows服务。我想从运行此虚拟机的本地计算机上运行的客户端与此WCF进行通信。我可以在本地运行该服务没有问题,但是当涉及与虚拟机上的服务进行通信时,我真的很难配置它。我想在不使用IIS的情况下使用TCP连接。
我尝试指定VM的地址,备用地址和端点但没有成功。你能告诉我什么是正确的配置吗?
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBindingConfiguration">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="WCFHostBehaviour" name="TestRunnerWCF.Service">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="NetTcpBindingConfiguration"
name="WCFHostNetTcpEndpoint" contract="TestRunnerWCF.IService" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
name="WCFHostMexTcpEndpoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://192.168.10.25/Service" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCFHostBehaviour">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
更新1: 我不知道如何在我的客户端添加服务引用。如果我使用localhost,我在本地计算机上运行服务,这是不可取的。
虚拟机在Hyper-V中运行,地址为192.168.10.25。我可以从本地机器ping它。我不使用任何端口转发。
我可以使用此配置在虚拟机上运行客户端:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="WCFHostNetTcpEndpoint">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://192.168.10.25/Service" binding="netTcpBinding"
bindingConfiguration="WCFHostNetTcpEndpoint" contract="ServiceReference1.IService"
name="WCFHostNetTcpEndpoint">
</endpoint>
</client>
</system.serviceModel>
但是当我尝试在本地计算机上运行客户端时,我无法连接到我的虚拟机。
Error: Cannot obtain Metadata from net.tcp://192.168.10.25/Service If this
is a Windows (R) Communication Foundation service to which you have access,
please check that you have enabled metadata publishing at the specified
address. For help enabling metadata publishing, please refer to the MSDN
documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata
Exchange Error URI: net.tcp://192.168.10.25/Service Metadata contains
a reference that cannot be resolved: 'net.tcp://192.168.10.25/Service'.
Could not connect to net.tcp://192.168.10.25/Service. The connection attempt
lasted for a time span of 00:00:21.0324561. TCP error code 10060: A
connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because
connected host has failed to respond 192.168.10.25:808. A connection
attempt failed because the connected party did not properly respond after a
period of time, or established connection failed because connected host has
failed to respond 192.168.10.25:808
答案 0 :(得分:0)
正如Reniuz指出的那样,VM中的防火墙阻止了我的连接。 原评:
因此您需要指定VM的IP地址。但首先,您需要确保可以访问它。尝试连接whit telnet。如果您无法连接,首先您可以做的是在VM的防火墙中添加入站规则(新规则 - >选择端口 - &gt; next-&gt;输入wcf服务端口 - &gt;完成)。很可能防火墙在您的VM wcf端口上阻止连接。 - Reniuz