开发者

What is the KnownType attribute analog for XML Serialization?

开发者 https://www.devze.com 2023-02-04 19:57 出处:网络
Are there any analogs of KnownTypeAttribute but for XmlSerializerClass? How I can configure known types for asmx web services?

Are there any analogs of KnownTypeAttribute but for XmlSerializerClass? How I can configure known types for asmx web services?

I created an .asmx web service. Now, client cannot serialize request to it. So, I want somethi开发者_运维百科ng like KnownTypesAttribute in order to specify which types serializer have to use.


I just had to add XmlIncludeAttribute to class which is used as input parameter of the web.service method. That makes client generate correct web reference and XmlSerializer will be abble serialize this class correctly.

<Xml.Serialization.XmlInclude(GetType(String()))> _
Public Class MssRequest
.........


You can pass an array of known types:

 XmlSerializer xs = new XmlSerializer(typeof(MyType),
new Type[] {typeof(MyNestedType)});

In this setting:

public class MyType
{

     public IMyInterface NestedType { // .... implemented by MyNestedType
0

精彩评论

暂无评论...
验证码 换一张
取 消