SOAP泛型类型的序列化 [英] SOAP generic type serialization

查看:132
本文介绍了SOAP泛型类型的序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经创建了一个类来包装与公共信息网络服务响应的有效载荷如下:

We have created a class to wrap the payload of web service response with common information as follows.

public class ItemResponse<T> : Response
    {
    /// <summary>
    /// constructor to set private properties Item and Status
    /// </summary>
    /// <param name="item"></param>
    /// <param name="status"></param>
    public ItemResponse(T item, ResponseStatusEnum status) : base(status)
    {
        _item = item;
    }

    public ItemResponse()
    {
    }


    public ItemResponse(ResponseStatusEnum status, System.Collections.Generic.List<ResponseError> errors) : base(status, errors)
    {
    }
    private T _item;

    public T Item
    {
        get
        {
            return _item;
        }
    }


}

的基类响应只是持有错误信息和响应的状态。将wsdl清楚地显示了这种反应的定义是ItemResponseOfType [类型名],但该项目类型信息从定义丢失。

The base class "Response" just holds error information and status of the the response. The wsdl clearly shows the definition of this response to be ItemResponseOfType[TypeName] but the item type information is missing from the definition.

我们尝试添加

[XmlInclude(typeof(TypeName))]

但无济于事。任何想法我们能做些什么来让SOAP串行器知道我们想要的项目类型的串行化?

but to no avail. Any ideas what we can do to let the SOAP serializer know we want the "Item" type serializing?

推荐答案

确定我们已经得到了这条底线。

OK we have got to the bottom of this.

其原来的XML序列化可以序列化泛型类型排序的。由于neontapir正确地指出泛型类型不完全XML序列化的支持,但它仍然可以序列化泛型类型,因为它创造类型的ItemResponseOfType [TheType]正如我在我的问题提及。

Its turns out that the XML Serializer can serialize generic types of a sort. As neontapir correctly points out Generic types are not fully supported by the XML Serializer but it can still serialise generic types as it creates types of ItemResponseOfType[TheType] as I mentioned in my question.

XML序列化程序只是不会去序列化的类型泛型类型。

The XML Serializer just wont de serialize the type to a generic Type.

我们的问题只是该财产是项只读,因此SOAP错过了Item属性了。我们只是需要让物业publicy可设置为如下修正

Our problem was simply that the property Item was read only and as a result SOAP missed the Item property out. We just needed to make the property publicy settable to fix as below

public class ItemResponse<T> : Response
{
/// <summary>
/// constructor to set private properties Item and Status
/// </summary>
/// <param name="item"></param>
/// <param name="status"></param>
public ItemResponse(T item, ResponseStatusEnum status) : base(status)
{
    Item = item;
}

public ItemResponse()
{
}


public ItemResponse(ResponseStatusEnum status, System.Collections.Generic.List<ResponseError> errors) : base(status, errors)
{
}

public T Item
{
     get; set;
}
}

这篇关于SOAP泛型类型的序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆