[英]How to host a public WCF service?
我正在嘗試創建一個tcp wcf服務,該服務將托管在沒有IIS的服務器上,並且無需身份驗證即可供公眾訪問。
這是我做的:
ServiceHost svh = new ServiceHost(typeof(MyService));
var tcpbinding = new NetTcpBinding(SecurityMode.None);
var location = "net.tcp://localhost:11111";
svh.AddServiceEndpoint(typeof(IMyService), tcpbinding, location);
svh.Open();
....
該服務在locashost上運行正常,但是當我在服務器上設置它時(添加了防火牆例外),客戶端崩潰並顯示一條消息:
The socket connection was aborted. This could be caused by an error processing
your message or a receive timeout being exceeded by the remote host, or an
underlying network resource issue. Local socket timeout was '00:00:59.7344663'.
這是客戶端配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IMyService">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://myserver:11111/"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IMyService"
contract="MyServer.IMyService" name="NetTcpBinding_IMyService" />
</client>
</system.serviceModel>
</configuration>
我應該改變什么才能工作?
我過去遇到過類似的問題,我通過在端點地址( ServiceHost
.ctor)中不使用localhost
來解決它,而是使用實際的機器名來代替。 此外,您可以在服務主機本身中定義地址,如下所示。
ServiceHost svh = new ServiceHost(typeof(MyService), new Uri("net.tcp://myserver:11111"));
var tcpbinding = new NetTcpBinding(SecurityMode.None);
svh.AddServiceEndpoint(typeof(IMyService), tcpbinding, "");
svh.Open();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.