【问题标题】:WCF: How to enforce MessageContractAttribute.IsWrapped=false generation?WCF:如何强制 MessageContractAttribute.IsWrapped=false 生成?
【发布时间】:2010-11-25 21:01:24
【问题描述】:

换句话说:如何更改 wcf 服务合同以从肥皂消息中删除额外的“消息”包装(采用 wsdl)?

我创建了 WCF 服务,合同是:

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

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

<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:e 级别丢失)

<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)。我可以看到生成的代码在生成的消息类附近使用 MessageContract.IsWrapperd=false,但我无法更改生成的代码,所以 .我应该以某种方式更改操作合同,并要求 wcf 使用正确的 MessageContract 为我生成消息。

【问题讨论】:

    标签: .net wcf contract


    【解决方案1】:

    我有一个想法:我应该以某种方式要求生成不

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

    但是

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

    追加:

    现在我知道该怎么做了:服务/操作合同中没有这样的选项来生成所需的消息合同,但可以创建自己的类,用消息合同属性标记它。

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

    【讨论】:

      猜你喜欢
      • 2011-03-02
      • 1970-01-01
      • 2015-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多