不能从我的局域网上的任何其他机器访问WCF REST服务
本文关键字:访问 机器 WCF REST 服务 其他 任何 我的 局域网 不能 | 更新日期: 2023-09-27 17:49:26
没有任何类似的问题对我有帮助。我相信这里的专家会……
我的问题是我托管一个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>
当我从LAN中的其他机器访问服务时,我得到这个错误:
System.ServiceModel。EndpointNotFoundException:没有端点在
http://yaniv-pc:8080/Test/123
收听,可以接受消息。这通常是由不正确的地址或SOAP操作引起的。详情请参见InnerException(如果存在)。--->system.net.webeexception:无法连接到远程服务器-->System.Net.Sockets.SocketException:尝试套接字操作不可达网络10.0.0.3:8080
任何想法?
假设您的服务是自托管的,请确保您已经使用netsh命令注册了端口,如下所示:
netsh http add urlacl url=http://+:8080/ user='everyone
也可以在禁用防火墙的情况下进行测试
你应该试着禁用你的防火墙或者试着添加一个带有port到防火墙的规则