我有一個WCF服務託管在遠程計算機上。我能夠連接到它並使用WPF應用程序完美地使用服務。我也希望能夠從不同機器上的不同Windows服務連接到WCF服務。我將app.config設置爲與WPF應用程序相同,但Windows服務將不會連接到WCF服務。以下是錯誤:從Windows服務連接到WCF服務
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.
下面是從Windows服務的app.config:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="ServiceIP" value="127.0.0.1"/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="lib" />
</assemblyBinding>
</runtime>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBindingEndpoint" closeTimeout="00:01:00"
openTimeout="00:00:10" receiveTimeout="00:10:00" sendTimeout="00:00:15"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8731/WCFService/" binding="netTcpBinding"
bindingConfiguration="NetTcpBindingEndpoint" contract="WCFService.IWCFService"
name="NetTcpBindingEndpoint">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
任何想法,爲什麼我可以用一個WPF應用程序正常連接,但不能從Windows服務?
編輯:
這裏是我正在創建中的代碼連接:
EndpointAddress ep = new EndpointAddress("net.tcp://" + remoteIP + ":8731/WCFService/");
InstanceContext context = new InstanceContext(this);
wcfObj = new WCFService.WCFServiceClient(context, "NetTcpBindingEndpoint", ep);
wcfObj.Subscribe();
編輯2:
感謝Huusom我能得到它通過更改運行該服務的帳戶進行工作。問題是我不想問安裝服務的用戶去搞亂服務帳戶。除此之外,我還有什麼可以做的嗎?我可以禁用某種安全性嗎?
您是否嘗試在代碼中設置連接以檢查它是否是實際連接問題而不是加載.config? – ChrFin 2012-01-27 17:44:57
這可能是很多事情。當DataContract的所有字段都未提供且這些字段未使用EmitDefaultValue = false標記時,我遇到過這個錯誤最多。如果你跟蹤你的WCF通信,如下所示:http://msdn.microsoft.com/en-us/library/ms733025.aspx,你可以追蹤它。 – Josh 2012-01-27 17:48:04
默認情況下,Windows服務沒有可執行文件位置的當前工作目錄。這可能會導致配置文件混亂。 – 2012-01-27 17:49:18