2

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

我的问题是我正在托管 WCF Rest 服务,我只能在本地访问它。LAN 上的任何其他计算机都无法访问它。

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

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 进行套接字操作

有任何想法吗?

4

2 回答 2

0

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

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

还可以尝试在禁用 PC 防火墙的情况下对其进行测试

于 2013-01-14T15:26:37.023 回答
0

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

于 2016-04-06T18:42:12.150 回答