2010-11-25 23 views
1

换句话说:如何更改wcf服务合约以从soap消息中删除附加的“消息”包装(采用wsdl)?WCF:如何强制执行MessageContractAttribute.IsWrapped = false生成?

我已创建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:电子水平遗漏)

<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的消息。

回答

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