[英]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.