0

我将尝试描述我的问题。我在代理类(由wsdl自动生成)中有一个方法,它接受一个BaseType类型的对象作为它的第一个参数。我尝试传递一个继承的类型,我得到了

xyz 类型不是预期的。使用 XmlInclude 或 SoapInclude 属性指定静态未知的类型

在搜索了很多时间后,我阅读了有关命名空间和 xmlinclude 属性的信息。所以最初我有

/// [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Web.Services .WebServiceBindingAttribute(Name="esDatabaseServersSoap", Namespace="http://smbsaas/foo/bar")] [System.Xml.Serialization.XmlIncludeAttribute(typeof(SomeOtherType))]
公共部分类 esDatabaseServers:Microsoft.Web.Services3。 WebServicesClientProtocol { private System.Threading.SendOrPostCallback GetRawSqlDatabasesPagedOperationCompleted; ....................................................
.. ..................................................

然后我尝试添加

[System.Web.Services.WebServiceBindingAttribute(Name="esDatabaseServersSoap", Namespace="http://smbsaas/foo/bar")] [System.Xml.Serialization.XmlIncludeAttribute(typeof(SomeOtherType))] [System.Xml. Serialization.XmlIncludeAttribute(typeof( MyInheritedType ))] 我添加了这一行
public partial class esDatabaseServers :

我有

System.Web.Services.Protocols.SoapException:System.Web.Services.Protocols.SoapException:服务器无法读取请求。---> System.InvalidOperationException: XML 文档中存在错误。---> System.InvalidOperationException:无法识别指定的类型:name='MyInheritedType', namespace="http://smbsaas/foo/bar", at 。

MyInheritedType 继承自 baseClass。

我真的不知道该怎么办。请问有什么想法吗?谢谢!

4

1 回答 1

0

您是否尝试过将 XmlInclude 属性放在基类中 - 如本文所述:Web 服务 - XmlInclude 在派生类而不是基类中?

但是,这只有在您拥有 web 服务时才有用。

如果只是为了一些增强(可能不是你的情况),你可以尝试使用部分类。

于 2014-10-02T05:54:56.257 回答