![](/img/trans.png)
[英]WCF Client not able to negotiate security access with Service running in a different machine
[英]Unable to access WCF Service from Client machine
無法從客戶端計算機訪問WCF服務
這兩個服務(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>
當我調用任何一種服務方法時,都會出現錯誤提示
無法連接到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相同:按照Tim的要求
<?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>
大概我會檢查三件事:
將服務引用添加到客戶端時,是從net.tcp://localhost:8010/WCFService.Service1/
添加它,還是從net.tcp://server17:8010/WCFService.Service1/
添加它?
如果要從server17添加它,請嘗試使用服務器的標准名稱-即server17.mydomain.com或其他名稱。
連接錯誤可能與您使用的端點地址有關-客戶端傳入的serverPrincipalName為“ host / server17.domain.com”,但是您嘗試連接到本地主機。
不能保證上述任何一個都是根本原因,但是它為您提供了一個起點。
編輯
您在baseAddress元素中指定了locahost,但在endpiont元素的address屬性中未指定任何內容。 這可能就是為什么它仍要進入本地主機的原因。
修改服務的配置文件以將baseAddress更改為:
<baseAddresses>
<add baseAddress="net.tcp://server17:8010/WCFService.Service1/" />
</baseAddresses>
或刪除baseAddresses並在端點中指定地址:
<endpoint address="net.tcp://server17:8010/WCFService.Service1/"
binding="netTcpBinding"
bindingConfiguration=""
name="netTcpEndPoint"
contract="WCFService.IService1" />
試試看。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.