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

半城伤御伤魂 提交于 2019-12-08 08:14:52

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/4280830/wcf-how-to-enforce-messagecontractattribute-iswrapped-false-generation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!