WSE 3.0 Web 服务未知的派生类型

发布于 2024-08-17 21:28:01 字数 788 浏览 4 评论 0原文

我有一个基于 WSE 3.0 的 Web 服务和一个 WinForms 客户端应用程序,该应用程序使用该服务的 References.cs 中定义的类型,但对它们进行子类化以提供客户端所需的一些附加功能。

但是,当我将子类的实例传递回 Web 服务时,即使我显式地转换回原始类型,我也会遇到可怕的情况:

使用 XmlInclude 或 SoapInclude 属性来指定静态未知的类型。

参考我的派生类型。

代码摘要:

public class DefinedInReferenceCs
{ 
    // ... 
}

public class ClientSubclass : DefinedInReferenceCs
{
    // My extra stuff
}

public class MyClient
{
    public CallTheWebService(ClientSubclass  obj)
    {
        // obj is an instance of ClientSubclass,  cast as DefinedInReferenceCs
        svc.MyMethod((DefinedInReferenceCs)obj); 
        // Throws an exception complaining that ClientSubclass is not statically known
    }
}

我可以通过显式创建 DefinedInReferenceCs 实例并执行相关字段的深层复制来解决此问题。有更好的办法吗?

I have a WSE 3.0 based web service, and a WinForms client application that makes use of the types defined in that service's References.cs, but subclasses them to provide some additional functionality required by the client.

However, when I pass an instance of the subclass back to the web service, even though I explicitly cast back to the original type, I get the dreaded:

Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.

in reference to my derived type.

Code summary:

public class DefinedInReferenceCs
{ 
    // ... 
}

public class ClientSubclass : DefinedInReferenceCs
{
    // My extra stuff
}

public class MyClient
{
    public CallTheWebService(ClientSubclass  obj)
    {
        // obj is an instance of ClientSubclass,  cast as DefinedInReferenceCs
        svc.MyMethod((DefinedInReferenceCs)obj); 
        // Throws an exception complaining that ClientSubclass is not statically known
    }
}

I can get around this by explicitly creating a DefinedInReferenceCs instance and performing a deep copy of the relevant fields. Is there a better way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁〃客ぐ 2024-08-24 21:28:01

由于 XML 序列化程序使用反射来处理对象,因此无法阻止它看到基类引用引用了派生类的实例。是的,您必须使用XmlInclude

OTOH,您是否考虑过使用部分类向原始代理类添加功能?这样,您就根本不需要派生类。

Since the XML Serializer uses Reflection to work with objects, there is no way to keep it from seeing that your base class reference references an instance of your derived class. Yes, you must use XmlInclude.

OTOH, have you considered using partial classes to add functionality to the original proxy classes? That way, you would not need a derived class at all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文