Web服务无法序列接口 [英] web service can't serialize an interface

查看:76
本文介绍了Web服务无法序列接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一个接口,这样:

I have an interface like so:

public interface IDocument : ISerializable
{
    Boolean HasBeenUploaded { get; set; }
    void ISerializable.GetObjectData(SerializationInfo, StreamingContext) { }
}



有三个文件,从这个继承,所有这些序列化就好了。但是,创建一个简单的Web服务时,什么也不做,在那里他们可以上传到...

There are three documents that inherit from this, all of which serialize just fine. But when creating a simple web service, that does nothing, where they can be uploaded to...

public class DCService : System.Web.Services.WebService
{
    [WebMethod]
    public Boolean ReceiveDocument(IDocument document)
    {
        DBIO io = new DBIO();

        return io.InsertIntoDB(document); // does nothing; just returns true
    }
}



我得到这个当试图运行它:无法序列接口的IDocument

I get this when trying to run it: "Cannot serialize interface IDocument"

我不明白为什么这会成为一个问题。我知道,有些人有遇到了麻烦,因为他们不希望强制子类实现自定义序列化,但我做的,到现在为止它已经成功了。

I'm not quite sure why this would be a problem. I know that some people have had trouble because they didn't want to force subclasses to implement custom serialization but I do, and up to this point it has been successful.

编辑>如果我创建个人webMethods的接受实现该接口的对象,它工作正常,但削弱了客户机/服务器之间的合同(并破坏其摆在首位接口的目的)

edit> If I create individual webmethods that accept the objects that implement the interface, it works fine, but that weakens the contract between the client/server (and undermines the purpose of having the interface in the first place)

推荐答案

您可能需要使用XmlInclude属性您的Web方法。 A示例可以在这里找到 。我们碰上之前这个问题,并增加了XmlInclude属性在客户端和某些Web服务方法,我们两个Web服务代理类。

You may need to use an XmlInclude attribute to your web method. A example can be found here. We have run into this issue before and have added XmlInclude attributes to both our web service proxy class on the client and to certain web service methods.

[WebMethod]
[XmlInclude(typeof(MyDocument))]
public Boolean ReceiveDocument(IDocument document)
{
    DBIO io = new DBIO();

    return io.InsertIntoDB(document); // does nothing; just returns true
}

这篇关于Web服务无法序列接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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