XmlInclude或SoapInclude

时间:2009-05-01 00:12:00

标签: web-services

我正在开发一个webservice,它返回我在webservice中定义的类数组。当我测试它时,我得到:“System.InvalidOperationException:不期望类型WebSite + HostHeader。使用XmlInclude或SoapInclude属性指定静态未知的类型。”

以下是代码的一部分:

[WebService(Namespace = "http://WebSiteInfo.Podiumcrm.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebSite : System.Web.Services.WebService
{
    public class WebSiteEntry
    {
        public string SiteName = "";
        public string Comment = "";
        public string IISPath = "";
        public int SiteID = 0;
        public ArrayList HostHeaders;

        public WebSiteEntry()
        {
        }
    }
    public class HostHeader
    {
        public string IPAddress = "";
        public int Port = 0;
        public string URL = "";

        public HostHeader()
        {
        }
    }


    [WebMethod(EnableSession = true)]
    [TraceExtension(Filename = @"C:\DotNetLogs\WebSiteServices.log")]
    public WebSiteEntry[] WebSites()
    {...}
}

当我尝试:

[WebService(Namespace = "http://WebSiteInfo.Podiumcrm.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[XmlInclude(typeof(WebSiteEntry))]
[XmlInclude(typeof(WebSiteProperty))]
[XmlInclude(typeof(HostHeader))]

public class WebSite : System.Web.Services.WebService
{...}

我得到:“找不到类型或命名空间名称XmlInclude(您是否缺少using指令或程序集引用?)”

指出可以给我编纂和执行的咒语的人!

...谢谢

1 个答案:

答案 0 :(得分:4)

根据您收到的错误:

找不到类型或命名空间名称“XmlInclude”(您是否缺少using指令或程序集引用?)

您似乎错过了System.Xml.Serialization Namespace。您可以完全限定XmlInclude类型,如下所示:

System.Xml.Serialization.XmlInclude(typeof(WebSiteProperty))

或通过using指令添加命名空间:

using System.Xml.Serialization