2011-01-27 115 views
1

我在WCF中遇到了一個令我瘋狂的問題。它是:WCF部署問題

由於EndpointDispatcher上的ContractFilter不匹配,無法在接收方處理具有Action'GetUserByUserNameAndPassword'的消息。這可能是因爲合同不匹配(發件人和收件人之間的操作不匹配)或發件人和收件人之間的綁定/安全性不匹配。檢查發送方和接收方是否有相同的合同和相同的綁定(包括安全要求,例如消息,傳輸,無)。

設置如下。我有一臺Web服務器在IIS 7中運行客戶端網站,該客戶端嘗試使用WCF與另一臺服務器進行通信,該服務器在IIS 7中具有SQL Server和託管WCF服務。

這兩臺機器位於同一個域中。

嘗試將其剝離爲無,我試圖讓這個工作沒有安全。客戶端的配置是這樣的:

<bindings> 
    <wsHttpBinding> 
     <binding name="wsHttpBinding_Normal"> 
     <security mode="None"/> 
     </binding> 
    </wsHttpBinding> 
</bindings> 

<client> 
    <endpoint address="http://192.168.1.10:3026/DS.Service/AuditLogger.svc" 
    binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_Normal" 
    contract="AuditLogger.IAuditLogger" name="wsHttpBinding_IAuditLogger"> 
     <identity> 
      <dns value="localhost" /> 
     </identity> 
    </endpoint> 
</client> 

然後在服務器上的配置是這樣的:

<bindings> 
    <wsHttpBinding> 
     <binding name="NormalTrafficBinding"> 
     <security mode="None"/> 
     </binding> 
    </wsHttpBinding> 
</bindings> 

<services> 
    <service name="DS.Service.ServiceImplementation.AuditLogger"> 
     <endpoint address="http://192.168.1.10:3026/DS.Service/AuditLogger.svc" 
     binding="wsHttpBinding" bindingConfiguration="NormalTrafficBinding" 
     contract="DS.Service.ServiceContracts.IAuditLogger"> 
      <identity> 
       <dns value="localhost" /> 
      </identity> 
     </endpoint> 
    </service> 
<services> 

本身看起來像這樣的方法:

[OperationContract(IsTerminating = false, IsInitiating = true, IsOneWay = false, AsyncPattern = false, Action = "GetUserByUserNameAndPassword")] 
    [FaultContract(typeof(DS.Service.FaultContracts.DSOfficeFault))] 
    System.Data.DataSet GetUserByUserNameAndPassword(string userName, string password); 
+0

你更新一個服務器端的代碼,忘了任何機會,以更新/重新創建另一臺機器上該服務器的客戶端代理? – 2011-01-27 15:14:25

回答

1

你必須定義兩端(服務器和客戶端)的合同相同。儘管它們都被稱爲IAuditLogger,但它們可能具有不同的簽名。嘗試在一個單獨的程序集中只放置一個IAuditLogger類,然後在兩個配置文件中引用它,或者確保兩個IAuditLogger具有相同的方法。

你可能有這樣的事情:

<client> 
<endpoint address="http://192.168.1.10:3026/DS.Service/AuditLogger.svc" 
binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_Normal" 
contract="AuditLogger.IAuditLogger" name="wsHttpBinding_IAuditLogger"> 
    <identity> 
     <dns value="localhost" /> 
    </identity> 
</endpoint> 

而且

<services> 
<service name="DS.Service.ServiceImplementation.AuditLogger"> 
    <endpoint address="http://192.168.1.10:3026/DS.Service/AuditLogger.svc" 
    binding="wsHttpBinding" bindingConfiguration="NormalTrafficBinding" 
    contract="AuditLogger.IAuditLogger"> 
     <identity> 
      <dns value="localhost" /> 
     </identity> 
    </endpoint> 
</service> 

+0

不,這是**不真實** - 如果您從Visual Studio中執行標準的「添加服務引用」,則客戶端代理將生成一個單獨的名稱空間,並且合約將是相同的它被序列化),但它存在於一個單獨的客戶端名稱空間中! – 2011-01-27 15:12:46