2012-09-14 113 views
1

我有一個WCF服務和兩個控制檯應用程序客戶端。一個WCF服務 - 兩個客戶端;一個客戶端不工作

服務:服務代碼是使用WCSF藍色工具從wsdl聯繫人創建的。

客戶端1:此客戶端正在使用通過瀏覽svc文件獲得的wsdl。這個瀏覽過的wsdl文件與合同wsdl文件略有不同。

客戶端2:此客戶端使用原始wsdl合同創建。

Cleint1工作正常。客戶端2不工作。什麼都可能是潛在的問題?

兩個客戶端的App.Config文件看起來很相似 - 只是名稱發生了變化。我認爲,問題將出現在客戶端C#代碼生成 - 最有可能在行動 - ReplyAction。這裏需要糾正哪些問題?

一個明顯的區別是在行動和ReplyAction

客戶端1:

行動= 「甕:lijo:演示:multiplyservice:計算:V1/ICalculationService/GetMultiplied」,ReplyAction =「甕: lijo:演示:multiplyservice:計算:V1/ICalculationService/GetMultipliedRe」 + 「sponse」

客戶端2:

行動= 「甕:lijo:演示:multiplyservice:計算:V1:getMultipliedIn」,ReplyAction = 「*」

跟蹤消息

與動作「甕的消息:由於EndpointDispatcher中的ContractFilter不匹配,lijo:demos:multiplyservice:calculation:v1:getMultipliedIn'無法在接收方處理。這可能是因爲合同不匹配(發件人和收件人之間的操作不匹配)或發件人和收件人之間的綁定/安全性不匹配。檢查發送方和接收方是否有相同的合同和相同的綁定(包括安全要求,例如消息,傳輸,無)。

EDIT

這可以通過改變操作和ReplyAction如下進行校正(從服務複製它)。

[System.ServiceModel.OperationContractAttribute(Action = "urn:lijo:demos:multiplyservice:calculation:v1/ICalculationService/getMultiplied", ReplyAction = "urn:lijo:demos:multiplyservice:calculation:v1/ICalculationService/getMultipliedRe" + 
     "sponse")] 

注:確保在服務的外殼是正確的(即,getMultiplied不GetMultiplied)從服務

複製是不是一個好的選擇,但它的工作原理是很重要的。什麼是正確的Action和ReplyAction?

另外,請您指出如何修改wsdl以使得ReplyAction在生成的客戶端代理中的正確?這是將它標記爲已回答的重要部分。

WCF: Actions, Asterisk and Metadata

WsdlExporter,其用於元數據發佈,將忽略具有星號的動作(動作都和ReplyAction)操作。

MSDN -ReplyAction Property

指定的服務星號指示WCF不答覆操作添加到該消息,如果你是直接針對編程的消息這是有用的。

參考

  1. WCF metadata missing operations

RestaurantData.xsd

<?xml version="1.0" encoding="utf-8" ?> 
<xs:schema id="RestaurantData" targetNamespace="urn:lijo:demos:multiplyservice:data:v1" 
    elementFormDefault="qualified" xmlns="urn:lijo:demos:multiplyservice:data:v1" 
    xmlns:mstns="urn:lijo:demos:multiplyservice:data:v1" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

    <xs:complexType name="multipliedResult"> 
    <xs:sequence> 
    <xs:element name="resultNumber" type="xs:int" /> 
    </xs:sequence> 
    </xs:complexType> 

    </xs:schema> 

原始合同WSDL

<definitions xmlns:import0="urn:lijo:demos:multiplyservice:messages:v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:import1="urn:lijo:demos:multiplyservice:data:v1" xmlns:tns="urn:lijo:demos:multiplyservice:calculation:v1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" name="CalculationService" targetNamespace="urn:lijo:demos:multiplyservice:calculation:v1" xmlns="http://schemas.xmlsoap.org/wsdl/"> 

<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" /> 
<types> 
<xsd:schema> 
    <xsd:import schemaLocation="C:\toolbox\LijosServiceApp\NewService\RestaurantMessages.xsd" namespace="urn:lijo:demos:multiplyservice:messages:v1" /> 
    <xsd:import schemaLocation="C:\toolbox\LijosServiceApp\NewService\RestaurantData.xsd" namespace="urn:lijo:demos:multiplyservice:data:v1" /> 
</xsd:schema> 
</types> 
<message name="getMultipliedIn"> 
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" /> 
<part name="parameters" element="import0:getMultiplied" /> 
</message> 
<message name="getMultipliedOut"> 
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" /> 
<part name="parameters" element="import0:getMultipliedResponse" /> 
</message> 
<portType name="CalculationServiceInterface"> 
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" /> 
<operation name="getMultiplied"> 
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" /> 
    <input message="tns:getMultipliedIn" /> 
    <output message="tns:getMultipliedOut" /> 
</operation> 
</portType> 
<binding name="BasicHttpBinding_CalculationServiceInterface" type="tns:CalculationServiceInterface"> 
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
<operation name="getMultiplied"> 
    <soap:operation soapAction="urn:lijo:demos:multiplyservice:calculation:v1:getMultipliedIn" style="document" /> 
    <input> 
    <soap:body use="literal" /> 
    </input> 
    <output> 
    <soap:body use="literal" /> 
    </output> 
</operation> 
</binding> 
<service name="CalculationServicePort"> 
<port name="CalculationServicePort" binding="tns:BasicHttpBinding_CalculationServiceInterface"> 
    <soap:address location="http://localhost/CalculationService" /> 
</port> 
</service> 
</definitions> 
+0

簡稱:http://stackoverflow.com/questions/5487791/wcf-contractfilter-mismatch -at-the-endpointdispatcher-exception和 http://stackoverflow.com/questions/1264431/wcf-contract-mismatch-problem – Lijo

+0

當你說第二個客戶端不工作時,你會得到什麼錯誤? –

+0

@MilanRaval例外是一樣貼在getMultipliedOut的地方問題 – Lijo

回答

6

我想通了。爲了別人的利益,我會在這裏解釋一下。

在此之前,請參考答案400 Bad Request Exception: Simple SOAP WCF service with small data一些調試的想法。

WCSF Blue工具這是由於Format SOAP Action選項。

我在使用WCSF Blue生成代碼時使用了「格式化Soap操作」。但是,雖然客戶端,我沒有使用該工具。這個不匹配是關鍵問題。

格式香皂操作迫使SOAP動作(行動ReplyAction)應用到每個經營合同遵循標準WCF格式

<namespace>/<service>/<operation>[Response] 

如果我沒有控制權客戶端,我不應該在WCSF Blue Tool中使用Format SOAP Action選項。

請參考Service works from wcfTestClient but fails in Console Application一個工作示例。

[還有一個問題 - 如果我無法控制客戶端仍然需要使用ReplyAction?在這種情況下,在客戶端和服務中使用xml格式的URI是什麼? ]

常見的調試思路:

  1. 確保良好的服務是通過使用wcfTestClient作爲How to turn on WCF tracing?

  2. 提到的(在VS型wcfTestClient命令提示符推出)

  3. 使用跟蹤

  4. 驗證配置值是否位於web.config/app.config而不是output.config中(在使用工具自動生成的情況下)

  5. 確認你是指適當的WSDL(它與運行服務的本地文件或URL?)

  6. 確定WSDL可以通過瀏覽SVC文件進行查看。元數據啓用

  7. 檢查它是否在服務中的「地址」相對路徑或絕對路徑

2

你是正確的,有在ReplyAction一個問題。當ReplyAction設置爲「*」時,WCF將忽略該操作。糾正答覆行動,您的運營合同將起作用。

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/41f5fe72-3ab3-4741-867e-a93119fe62aa

+1

使用getMultipliedResponse跟蹤消息,因爲ReplyAction應該是(「OperationName +‘迴應’),並在你的情況操作名GetMultiplied –

+1

行動=」甕:lijo :demos:multiplyservice:calculation:v1:getMultipliedIn「,ReplyAction =」urn:lijo:demos:multiplyservice:calculation:v1:getMultipliedInResponse「。另一個好博客:http://shishkin.wordpress.com/2007/03/21/wcf-actions-asterisk-and-metadata/ –

+0

實際上,這並沒有奏效,當我從服務中複製確切的Action和ReplyAction時,它可以工作;但那是不可接受的。是否有辦法強制工具生成所需的ReplyAction? – Lijo

相關問題