一个WCF服务 - 两个客户端;一个客户端不起作用

时间:2012-09-14 07:57:39

标签: c# .net wcf contract-first

我有一个WCF服务和两个控制台应用客户端。

服务:使用WCSF Blue工具从wsdl联系人创建服务代码。

客户端1:此客户端正在使用通过浏览svc文件获得的wsdl。此浏览的wsdl文件与合同wsdl文件略有不同。

客户端2:此客户端是使用原始wsdl合同创建的。

Cleint1工作正常。客户端2无法正常工作。什么都可能是潜在的问题?

两个客户端的App.Config文件看起来相似 - 只有名称更改。我认为,问题将出现在客户端生成的C#代码中 - 最有可能出现在 Action - ReplyAction 中。需要在这里纠正什么?

一个明显的区别在于Action和ReplyAction

客户1:

  

Action =“urn:lijo:demos:multiplyservice:calculation:v1 / ICalculationService / GetMultiplied”,ReplyAction =“urn:lijo:demos:multiplyservice:calculation:v1 / ICalculationService / GetMultipliedRe”+               “sponse”

客户2:

  

Action =“urn:lijo:demos:multiplyservice:calculation:v1:getMultipliedIn”,ReplyAction =“*”

跟踪消息

  

由于EndpointDispatcher上的ContractFilter不匹配,因此无法在接收方处理具有操作'urn:lijo:demos:multiplyservice:calculation:v1:getMultipliedIn'的消息。这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配。检查发件人和收件人是否具有相同的合同和相同的约束(包括安全要求,例如邮件,传输,无)。

修改

这可以通过更改Action和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忽略了使用星号操作的操作(Action和ReplyAction)。

来自MSDN -ReplyAction Property

  

在服务中指定星号指示WCF不向邮件添加回复操作,如果您直接对邮件进行编程,这非常有用。

参考

  1. WCF metadata missing operations

  2. 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>
    

2 个答案:

答案 0 :(得分:6)

我明白了。为了别人的利益,我将在此解释。

在此之前,请参阅400 Bad Request Exception: Simple SOAP WCF service with small data的答案以获取一些调试建议。

这归因于Format SOAP Action工具中的WCSF Blue选项。

我在使用WCSF Blue生成代码时使用了“格式化肥皂操作”。但是在客户端,我没有使用该工具。这种不匹配是关键问题。

格式化肥皂操作强制应用于每个操作合同的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确保服务良好(在VS命令提示符下键入wcfTestClient以启动)

  2. 使用How to turn on WCF tracing?

  3. 中提到的跟踪
  4. 验证配置值是否在web.config / app.config中,而不是在output.config中(如果使用工具自动生成)

  5. 验证您是否正在引用正确的wsdl(是运行服务的本地文件还是网址?)

  6. 验证是否可以通过浏览svc文件查看wsdl。元数据已启用

  7. 检查服务中“地址”中的相对路径或绝对路径

答案 1 :(得分:2)

你是对的,在ReplyAction中存在问题。当ReplyAction设置为“*”时,WCF将忽略该操作。更正您的操作合同的ReplyAction将起作用。

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