从WSDL更正WCF服务服务器端存根

时间:2010-09-11 00:24:19

标签: wcf wsdl

我有以下WSDL

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:tns="${namespace}" xmlns:wsr="http://www.openuri.org/2002/10/soap/reliability/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap12enc="http://www.w3.org/2003/05/soap-encoding" xmlns:conv="http://www.openuri.org/2002/04/wsdl/conversation/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="${namespace}">
 <message name="addADetails">
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string0">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string1">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string2">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string3">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:int" name="intVal">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string4">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string5">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string6">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string7">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string8">
  </part>
 </message>
 <message name="addADetailsResponse">
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="result">
  </part>
 </message>
 <message name="addBDetails">
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string0">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string1">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string2">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string3">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string4">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string5">
  </part>
 </message>
 <message name="addBDetailsResponse">
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="result">
  </part>
 </message>
 <message name="deleteCDetails">
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string0">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string1">
  </part>
 </message>
 <message name="deleteCDetailsResponse">
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="result">
  </part>
 </message>
 <message name="queryDDetails">
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string0">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string1">
  </part>
 </message>
 <message name="queryDDetailsResponse">
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="result">
  </part>
 </message>
 <message name="queryEDetails">
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string0">
  </part>
 </message>
 <message name="queryEDetailsResponse">
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="result">
  </part>
 </message>
 <message name="updateFDetails">
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string0">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string1">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string2">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string3">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:int" name="intVal">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string4">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string5">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string6">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string7">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string8">
  </part>
 </message>
 <message name="updateFDetailsResponse">
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="result">
  </part>
 </message>
 <message name="updateGDetails">
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string0">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string1">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string2">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string3">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string4">
  </part>
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="string5">
  </part>
 </message>
 <message name="updateGDetailsResponse">
  <part xmlns:partns="http://www.w3.org/2001/XMLSchema" type="partns:string" name="result">
  </part>
 </message>
 <portType name="TestServicePort">
  <operation name="addADetails">
   <input message="tns:addADetails">
   </input>
   <output message="tns:addADetailsResponse">
   </output>
  </operation>
  <operation name="addBDetails">
   <input message="tns:addBDetails">
   </input>
   <output message="tns:addBDetailsResponse">
   </output>
  </operation>
  <operation name="deleteCDetails">
   <input message="tns:deleteCDetails">
   </input>
   <output message="tns:deleteCDetailsResponse">
   </output>
  </operation>
  <operation name="queryDDetails">
   <input message="tns:queryDDetails">
   </input>
   <output message="tns:queryDDetailsResponse">
   </output>
  </operation>
  <operation name="queryEDetails">
   <input message="tns:queryEDetails">
   </input>
   <output message="tns:queryEDetailsResponse">
   </output>
  </operation>
  <operation name="updateFDetails">
   <input message="tns:updateFDetails">
   </input>
   <output message="tns:updateFDetailsResponse">
   </output>
  </operation>
  <operation name="updateGDetails">
   <input message="tns:updateGDetails">
   </input>
   <output message="tns:updateGDetailsResponse">
   </output>
  </operation>
 </portType>
 <binding type="tns:TestServicePort" name="TestServicePort">
   <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
  <operation name="addADetails">
    <soap:operation style="rpc" soapAction=""/>
   <input>
     <soap:body namespace="${namespace}" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
   </input>
   <output>
     <soap:body namespace="${namespace}" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
   </output>
  </operation>
  <operation name="addBDetails">
    <soap:operation style="rpc" soapAction=""/>
   <input>
     <soap:body namespace="${namespace}" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
   </input>
   <output>
     <soap:body namespace="${namespace}" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
   </output>
  </operation>
  <operation name="deleteCDetails">
    <soap:operation style="rpc" soapAction=""/>
   <input>
     <soap:body namespace="${namespace}" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
   </input>
   <output>
     <soap:body namespace="${namespace}" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
   </output>
  </operation>
  <operation name="queryDDetails">
    <soap:operation style="rpc" soapAction=""/>
   <input>
     <soap:body namespace="${namespace}" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
   </input>
   <output>
     <soap:body namespace="${namespace}" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
   </output>
  </operation>
  <operation name="queryEDetails">
    <soap:operation style="rpc" soapAction=""/>
   <input>
     <soap:body namespace="${namespace}" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
   </input>
   <output>
     <soap:body namespace="${namespace}" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
   </output>
  </operation>
  <operation name="updateFDetails">
    <soap:operation style="rpc" soapAction=""/>
   <input>
     <soap:body namespace="${namespace}" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
   </input>
   <output>
     <soap:body namespace="${namespace}" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
   </output>
  </operation>
  <operation name="updateGDetails">
    <soap:operation style="rpc" soapAction=""/>
   <input>
     <soap:body namespace="${namespace}" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
   </input>
   <output>
     <soap:body namespace="${namespace}" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
   </output>
  </operation>
 </binding>
 <service name="TestService">
  <port name="TestServicePort" binding="tns:TestServicePort">
    <soap:address location="http://testserver:7001/test/TestService"/>
  </port>
 </service>
</definitions>

我有一个现有的代理类,它调用WSDL描述的Web服务。我必须创建一个可以使用相同代理类调用的新WCF服务。 我使用ThinkTecture的WSCF.blue webservices契约第一个工具来生成WCF服务端存根:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="${namespace}", ConfigurationName="ITestServicePort")]
public interface ITestServicePort
{

    [System.ServiceModel.OperationContractAttribute(Action="${namespace}/ITestServicePort/addADetails", ReplyAction="${namespace}/ITestServicePort/addADetailsResponse")]
    [System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true, Use=System.ServiceModel.OperationFormatUse.Encoded)]
    [return: System.ServiceModel.MessageParameterAttribute(Name="result")]
    string addADetails(string @string, string string0, string string1, string string2, string string3, int intVal, string string4, string string5, string string6, string string7, string string8);

    [System.ServiceModel.OperationContractAttribute(Action="${namespace}/ITestServicePort/addBDetails", ReplyAction="${namespace}/ITestServicePort/addBDetailsResponse")]
    [System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true, Use=System.ServiceModel.OperationFormatUse.Encoded)]
    [return: System.ServiceModel.MessageParameterAttribute(Name="result")]
    string addBDetails(string @string, string string0, string string1, string string2, string string3, string string4, string string5);

    [System.ServiceModel.OperationContractAttribute(Action="${namespace}/ITestServicePort/deleteCDetails", ReplyAction="${namespace}/ITestServicePort/deleteCDetailsResponse")]
    [System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true, Use=System.ServiceModel.OperationFormatUse.Encoded)]
    [return: System.ServiceModel.MessageParameterAttribute(Name="result")]
    string deleteCDetails(string @string, string string0, string string1);

    [System.ServiceModel.OperationContractAttribute(Action="${namespace}/ITestServicePort/queryDDetails", ReplyAction="${namespace}/ITestServicePort/queryDDetailsResponse")]
    [System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true, Use=System.ServiceModel.OperationFormatUse.Encoded)]
    [return: System.ServiceModel.MessageParameterAttribute(Name="result")]
    string queryDDetails(string @string, string string0, string string1);

    [System.ServiceModel.OperationContractAttribute(Action="${namespace}/ITestServicePort/queryEDetails", ReplyAction="${namespace}/ITestServicePort/queryEDetailsResponse")]
    [System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true, Use=System.ServiceModel.OperationFormatUse.Encoded)]
    [return: System.ServiceModel.MessageParameterAttribute(Name="result")]
    string queryEDetails(string @string, string string0);

    [System.ServiceModel.OperationContractAttribute(Action="${namespace}/ITestServicePort/updateFDetails", ReplyAction="${namespace}/ITestServicePort/updateFDetailsResponse")]
    [System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true, Use=System.ServiceModel.OperationFormatUse.Encoded)]
    [return: System.ServiceModel.MessageParameterAttribute(Name="result")]
    string updateFDetails(string @string, string string0, string string1, string string2, string string3, int intVal, string string4, string string5, string string6, string string7, string string8);

    [System.ServiceModel.OperationContractAttribute(Action="${namespace}/ITestServicePort/updateGDetails", ReplyAction="${namespace}/ITestServicePort/updateGDetailsResponse")]
    [System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true, Use=System.ServiceModel.OperationFormatUse.Encoded)]
    [return: System.ServiceModel.MessageParameterAttribute(Name="result")]
    string updateGDetails(string @string, string string0, string string1, string string2, string string3, string string4, string string5);
}

问题是,当我使用现有代理类调用我的新服务时,它失败并出现SoapHeaderException:

  

带有Action''的消息不能   由于a,在接收器处理   ContractFilter不匹配   EndpointDispatcher。这可能是   因为合同不匹配   (发件人和发件人之间不匹配的行为)   接收者)或绑定/安全   发件人和发件人之间不匹配   接收器。检查发件人和   接收者有相同的合同和   相同的绑定(包括安全性   要求,例如消息,运输,   无)。

当我将OperationContractAttribute中的一个Action成员更改为空字符串时,我可以成功调用该操作。当我尝试更改多个Action以清空相同的调用失败时出现以下错误:

  

客户端找到了响应内容类型   '',但预计'text / xml'。该   请求失败且回复为空。

好像你不能有一个空Action的多个操作。那是对的吗? 我该如何解决这个问题?有什么建议吗?

由于

1 个答案:

答案 0 :(得分:1)

WCF中的默认行为使用SOAP Action来选择必须处理接收调用的操作。因此,OparationContract中的Action和ReplyAction参数必须对于单个服务是唯一的。

您需要通过“正文”路由您的请求。 WCF samples包含按body元素进行路由的示例。使用相同的方法,但不是通过顶级包装元素进行路由,而是必须根据您收到的参数决定调用哪个操作。 WSDL描述的服务不使用包装元素。