从文件系统反序列化SOAP消息

时间:2015-10-29 11:45:00

标签: c# wcf soap

我以前连接到通过WSDL文件定义的WCF端点。一切都很棒,我通过;

检索数据
var client = new ElementRetrieval_RPCClient();
var header = new header();
var elements = client.getAllElements(ref header, new getAllElementsRequest()).meList;

// Loop over elements.

然而,由于荒谬的策略,我的应用程序现在必须解析文件中的SOAP响应(并依赖第三方向我发出SOAP请求,并将响应转储到文件中以供我收集)。

我试过了;

var converter = TypedMessageConverter.Create(typeof(getAllElementsResponse), "getAllElementsResponse", "", new XmlSerializerFormatAttribute());
var reader = XmlTextReader.Create(file);
var message = Message.CreateMessage(MessageVersion.Soap11, "getAllElementsResponse", reader);
var obj = (getAllElementsResponse) converter.FromMessage(message);

...但这会使obj的属性保持为null(尽管不会引发/记录错误)。我也试过了:

var reader = XmlTextReader.Create(file);
var message = Message.CreateMessage(MessageVersion.Soap11, "getAllElementsResponse", reader);
var obj = message.GetBody<getAllElementsResponse>();

...但是SerializationException

失败了
  

其他信息:期望来自命名空间“http://schemas.datacontract.org/2004/07/ElementRetrieval”的元素“getAllElementsResponse”。遇到名为“getAllElementsResponse”的“元素”,命名空间“http://www.example.org/mri/xsd/mer/v1”。

...这里,“遇到”命名空间是正确的;但我不知道如何告诉GetBody<T>() 期望该命名空间?

getAllElementsResponse类(由WCF自动生成)如下所示(如果属性很重要):

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class getAllElementsResponse {

    [System.ServiceModel.MessageHeaderAttribute(Namespace="http://www.example.org/fmw/xsd/hdr/v1")]
    public ElementRetrieval.header header;

    [System.ServiceModel.MessageBodyMemberAttribute(Name="getAllElementsResponse", Namespace="http://www.example.org/mri/xsd/mer/v1", Order=0)]
    public ElementRetrieval.MultipleMeObjectsResponseType getAllElementsResponse1;

    public getAllElementsResponse() {
    }

    public getAllElementsResponse(ElementRetrieval.header header, ElementRetrieval.MultipleMeObjectsResponseType getAllElementsResponse1) {
        this.header = header;
        this.getAllElementsResponse1 = getAllElementsResponse1;
    }
}

... getAllElements方法具有以下属性:

// CODEGEN: Generating message contract since the operation getAllElements is neither RPC nor document wrapped.
[System.ServiceModel.OperationContractAttribute(Action="getAllElements", ReplyAction="*")]
[System.ServiceModel.FaultContractAttribute(typeof(ElementRetrieval.getAllElementsException), Action="getAllElements", Name="getAllElementsException", Namespace="http://www.example.com/mri/xsd/mer/v1")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(xxx))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(xxx))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(xxx))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(xxx))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(xxx))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(xxx))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(xxx))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(xxx))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(xxx))]

任何人都可以发现为什么这些方法都不起作用,并建议修复/解决?

0 个答案:

没有答案