WCF:如何执行MessageContractAttribute.IsWrapped =假的一代?WCF、MessageContractAttribute、IsWrapped

2023-09-04 04:49:55 作者:脚毛长无法自拔

在换句话说:如何更改WCF服务合同,从SOAP消息中删除额外的信息的包装(采用WSDL)

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

我创建WCF服务,这契约是:

I have created WCF service which contract is:

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

所以,我的SC现在接受这样的消息

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>

但传统的客户端发送这样的邮件(邮件的 EPR:电子水平遗漏)

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

确定。我从零创建WSDL,首先移除消息包装,然后已生成合同样本(CS)。我可以看到生成的code使用MessageContract.IsWrapperd =假附近产生的消息类,但我不能改变产生code,所以。我应该以某种方式改变经营合同,并要求WCF来为我留言右MessageContract。

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"/>

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

追加:

现在我知道如何做到这一点:有在服务/运营合同,以生成所需的消息的合同没有这样的选择,但有可能只是创建自己的类,它有消息协定属性标记

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