C# 从SOAP消息获取MessageContract/XmlType

C# 从SOAP消息获取MessageContract/XmlType,c#,wcf,soap,C#,Wcf,Soap,我很难通过向工作中添加服务引用来添加服务。我可以毫无疑问地呼叫服务,并得到回复(我可以在Fiddler中看到): 客户: public partial class SoapClient : System.ServiceModel.ClientBase<Soap>, Soap { executeResponse1 Soap.execute(executeRequest request) { return base.Channel.execute(request

我很难通过向工作中添加服务引用来添加服务。我可以毫无疑问地呼叫服务,并得到回复(我可以在Fiddler中看到):

客户:

public partial class SoapClient : System.ServiceModel.ClientBase<Soap>, Soap {

    executeResponse1 Soap.execute(executeRequest request) {
        return base.Channel.execute(request);
    }

    public executeResponse execute(execute execute1) {
        executeRequest inValue = new executeRequest();
        inValue.execute = execute1;
        executeResponse1 retVal = ((Soap)(this)).execute(inValue);
        return retVal.executeResponse;
    }

}
执行者响应:

[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.serviceprovider.com/service")]
public partial class executeResponse : object, System.ComponentModel.INotifyPropertyChanged {

    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
    public string request_number { get; set; }

}
我不知道如何从SOAP响应返回到修复此问题。如有任何建议,将不胜感激。

据此:

名称空间=”http://www.serviceprovider.com/service"

WCF希望主体下的SOAP元素具有上述名称空间。然而,它们是空的。如果您可以更改结果soap(即使只是暂时通过模拟来进行测试),请尝试用以下内容替换body元素:

<SOAP-ENV:Body xmlns="http://www.serviceprovider.com/service">

否则,请尝试在代理代码中设置Namespace=“”(我不确定WCF是否允许)。您还可以用空字符串替换WSDL中的这个名称空间,空字符串在生成代理方面可能更健壮一些


最后,如果这没有帮助,请基于此WSDL(或直接基于代理中的数据契约)设置WCF服务,并查看它返回的soap与实际服务返回的soap有何不同。

您是我的英雄!只需将名称空间更改为空白即可。
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class executeResponse1 {

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.serviceprovider.com/service", Order=0)]
    public executeResponse executeResponse;

}
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.serviceprovider.com/service")]
public partial class executeResponse : object, System.ComponentModel.INotifyPropertyChanged {

    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
    public string request_number { get; set; }

}
<SOAP-ENV:Body xmlns="http://www.serviceprovider.com/service">