繁体   English   中英

无法从局域网上的任何其他计算机访问WCF REST服务

[英]Can't Access WCF REST service from any other machine on my local area network

任何类似的问题都没有帮助我。 我相信这里的专家会..

我的问题是我正在托管WCF Rest服务,并且只能在本地访问它。 局域网上的任何其他计算机将无法访问它。

这就是我托管服务的方式(此服务在控制台应用程序中运行)

WebServiceHost host = new WebServiceHost(typeof(MyRestService), new Uri("http://Yaniv-PC:8080/Test"));

这是服务合同:

[ServiceContract]
public interface IMyRestService
{
    [OperationContract]
    [WebInvoke(Method = "GET", 
        ResponseFormat = WebMessageFormat.Xml, 
        BodyStyle = WebMessageBodyStyle.Wrapped, 
        UriTemplate = "/{id}")]
    string GetData(string id);
}

这是app.config文件(仅serviceModel部分)

<system.serviceModel>
<services>
  <service behaviorConfiguration="MyRestServiceBehavior" name="ServiceHostApp.MyRestService">
    <endpoint address="" binding="webHttpBinding" contract="ServiceHostApp.IMyRestService" behaviorConfiguration="web">
      <identity>
        <dns value="Yaniv-PC" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="MyRestServiceBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
</system.serviceModel>

当我打开浏览器并导航到: http://yaniv-pc:8080/test/123

我得到这个:

<?xml version="1.0"?>
<GetDataResponse xmlns="http://tempuri.org/">
    <GetDataResult>You sent server 123</GetDataResult>
</GetDataResponse>

当我从局域网中的其他计算机访问服务时,出现此错误:

System.ServiceModel.EndpointNotFoundException:在http://yaniv-pc:8080/Test/123上没有侦听终结点的端点可以接受该消息。 这通常是由不正确的地址或SOAP操作引起的。 有关更多详细信息,请参见InnerException(如果存在)。 ---> System.Net.WebException:无法连接到远程服务器---> System.Net.Sockets.SocketException:尝试了对不可达网络的套接字操作10.0.0.3:8080

有任何想法吗?

假设您正在自托管服务,请确保已使用netsh命令注册了端口,如下所示:

netsh http add urlacl url=http://+:8080/ user=\everyone

另外尝试在禁用PC防火墙的情况下对其进行测试

您应该尝试禁用防火墙或尝试向防火墙添加带有端口的规则。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM