無法從客戶機訪問WCF服務無法從客戶機訪問WCF服務
- 我有三個項目:WCF服務(VS-2008),Windows服務(VS-2008),客戶端(VS- 2005)
- WCF服務具有NetTcpBinding的
- 此服務託管作爲Windows服務,而不是在IIS
的基址既服務(WCF和Windows)是
net.tcp://localhost:8010/WCFService.Service1/
現在,當我添加服務參考客戶端項目,該項目是VS-2005,它更新我的app.config文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="netTcpEndPoint" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" 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:8010/WCFService.Service1/"
binding="netTcpBinding" bindingConfiguration="netTcpEndPoint"
contract="Client.Service1.IService1"
name="netTcpEndPoint">
<identity>
<servicePrincipalName value="host/server17.domain.com" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
,並增加了Service1.map文件
<?xml version="1.0" encoding="utf-8"?>
<ServiceReference>
<ProxyGenerationParameters
ServiceReferenceUri="net.tcp://server17:8010/WCFService.Service1/"
Name="Service1"
NotifyPropertyChange="False"
UseObservableCollection="False">
</ProxyGenerationParameters>
<EndPoints>
<EndPoint
Address="net.tcp://localhost:8010/WCFService.Service1/"
BindingConfiguration="netTcpEndPoint"
Contract="Client.Service1.IService1"
>
</EndPoint>
</EndPoints>
</ServiceReference>
當我打電話的任何服務方法時,我得到一個錯誤,說明
無法控制nect to net.tcp:// localhost:8010/WCFService.Service1 /。 連接嘗試持續時間跨度爲00:00:02.0063936。 TCP 錯誤代碼10061:無法建立連接,因爲目標機器 主動拒絕它127.0.0.1:8010。
至少它應該是net.tcp://server17:8010/WCFService.Service1/
我已經嘗試與客戶端項目server17
更換localhost
......但沒有運氣
我應該怎麼改變,使其工作?請幫忙。
這是我的WCF服務的App.config中是相同的Windows服務的 的app.config:由蒂姆
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="WCFService.ServiceBehavior"
name="WCFService.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
name="netTcpEndPoint" contract="WCFService.IService1" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
name="mexTcpEndPoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8010/WCFService.Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCFService.ServiceBehavior">
<serviceMetadata httpGetEnabled="False" />
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
您的服務和您的客戶在同一臺機器上運行嗎? 這是一個明確的網絡相關的錯誤,所以我想你的服務沒有運行或不綁定端口8010.打開命令提示符,並嘗試在運行服務的機器上連接「telnet localhost 8010」。如果你沒有連接,你的服務肯定不會聽8010端口。 – Jan