WCF无法序列化包装的消息

时间:2012-11-14 20:23:45

标签: c# wcf web-services serialization soap

简而言之,我尝试使用WCF 手动构建Web服务使用者;这是SOAP响应:

<s:Body xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <AMethodResponse xmlns="http://v_namespace">
        <ReturnObjectHeader>
            <Field5>V5</Field5>
            <Field3>V5</Field3>
            <Field4>V5</Field4>
        </ReturnObjectHeader>
    </AMethodResponse>
</s:Body>

不久,下面是我的C#代码中的相关部分(之后我提供了跟踪结果):

[System.ServiceModel.MessageContractAttribute(WrapperName = "AMethodResponse", IsWrapped = true, WrapperNamespace = "http://v_namespace")]
public partial class ReturnObjectWrapper
{
    private ReturnObject _ReturnObjectHeader;

    [System.ServiceModel.MessageBodyMemberAttribute(Name = "ReturnObjectHeader", Namespace = "http://v_namespace")]
    public ReturnObject ReturnObjectHeader
    {
        get { return _ReturnObjectHeader; }
        set { _ReturnObjectHeader = value; }
    }
}

[System.ServiceModel.MessageContractAttribute(IsWrapped = false)]
public partial class ReturnObject
{
    private string _Field5;
    private string _Field3;
    private string _Field4;

    [System.ServiceModel.MessageBodyMemberAttribute(Name = "Field5", Namespace = "http://v_namespace")]
    public string Field5
    {
        get { return _Field5; }
        set { _Field5 = value; }
    }

    [System.ServiceModel.MessageBodyMemberAttribute(Name = "Field3", Namespace = "http://v_namespace")]
    public string Field3
    {
        get { return _Field3; }
        set { _Field3 = value; }
    }

    [System.ServiceModel.MessageBodyMemberAttribute(Name = "Field4", Namespace = "http://v_namespace")]
    public string Field4
    {
        get { return _Field4; }
        set { _Field4 = value; }
    }
}

以下是跟踪结果:

Description: An unrecognized element was encountered in the XML during deserialization which was ignored.
Element: http://v_namespace:Field5
NOTE: Same for Field4 and 3

我做错了什么?

1 个答案:

答案 0 :(得分:0)

this site找到;添加ServiceBehavior属性对我有用,即:

[ServiceBehavior(Namespace="http://v_namespace")]
相关问题