开发者

correct WCF service server side stub from WSDL

I have the following 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>

I have an existing proxy class that calls the webservice described by the WSDL. I have to create a new WCF service that can be called with the same proxy class. I used the WSCF.blue webservices contract first tool from ThinkTecture to generate a WCF service side stub:

[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}/ITes开发者_开发百科tServicePort/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);
}

The problem is when I use the existing proxy class to call my new service it fails with a SoapHeaderException:

The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

When I change one of the Action members in the OperationContractAttribute to an empty string I can call that operation successfully. When I try and change more than one Action to empty the same call fails with the following error:

Client found response content type of '', but expected 'text/xml'. The request failed with an empty response.

It seems as if you cant have more than one operation with an empty Action. Is that correct? How would I solve this problem? Any suggestions?

Thanks


Default behavior in WCF uses SOAP Action to choose which operation has to handle incomming call. For that reason Action and ReplyAction parameters in OparationContract has to be unique for single service.

You need to route your request by "body". WCF samples contains example of routing by body element. Use the same approach but instead of routing by top level wrapping element you will have to decide which operation has be called based on parameters you receive. Service described by WSDL doesn't use wrapping element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜