开发者

WCF: How to enforce MessageContractAttribute.IsWrapped=false generation?

开发者 https://www.devze.com 2023-01-27 13:03 出处:网络
In other words:How to change wcf service contract to remove additional \"message\'s\" wrapper from soap message (adopt wsdl)?

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

<s开发者_运维问答oapenv: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.


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;
    }
}
0

精彩评论

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