Question

In other words: How to change wcf service contract to remove additional "message's" wrapper from soap message (adopt wsdl)?

I have created WCF service which contract is:

   [ServiceContract(Namespace = "http://blabla/", Name = "DiagnosticApplication")]
   public interface IReceiveApplication
   {
        [OperationContract]
        string Test(XmlElement e);
   }

So my SC accepts now such messages

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:epr="http://blabla/">
     <soapenv:Header/>
     <soapenv:Body>
        <epr:Test>
           <epr:e>
             <anyxml/>
           </epr:e>
        </epr:Test>
     </soapenv:Body>
</soapenv:Envelope>

but legacy client sends such messages (message's epr:e level missed)

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:epr="http://blabla/">
    <soapenv:Header/>
    <soapenv:Body>
        <epr:Test>
          <anyxml/>
        </epr:Test>
    </soapenv:Body>
</soapenv:Envelope>

Ok. I have created "wsdl" from zero, first of all with removed message wrappers and then have generated sample contract (cs). I can see that generated code uses MessageContract.IsWrapperd=false near generated message classes, but I can't change generated code, so . I should somehow change operation contract, and ask wcf to generate for me messages with right MessageContract.

Was it helpful?

Solution

I have an idea: I should somehow ask to generate not

<wsdl:part name="parameters" element="tns:Test"/>

but

<wsdl:part name="parameters" type="xsd:any"/>

APPEND:

And now I know how do it: there are no such option in the service/operation contract to generate required message contract, but it is possible just create own class, mark it with message contract attribute.

[ServiceContract(Namespace = "http://blabla/", Name = "DiagnosticApplication")]
public interface IReceiveApplication
{
    [OperationContract]
    string Test(XmlElement  e);
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(IsWrapped = false)]
public partial class MessageRequest
{

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "", Order = 0)]
    public XmlElement parameters;

    public RCMR_IN000004FI01Request(){}

    public RCMR_IN000004FI01Request(XmlElement parameters)
    {
        this.parameters = parameters;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top