简体   繁体   English

无法序列化System.ComponentModel.ISite类型的成员System.ComponentModel.MarshalByValueComponent.Site,因为它是接口

[英]Cannot serialize member System.ComponentModel.MarshalByValueComponent.Site of type System.ComponentModel.ISite because it is an interface

I am using visual basic 2012, i have created a web services with following code.Where i have two method GetConnection() and Insert(). 我正在使用Visual Basic 2012,我用以下代码创建了一个Web服务。在这里我有两个方法GetConnection()和Insert()。 I getting connection ihave wrritten the code to get the database string.In Inert method i am inserting the value into EMP table with following code: 我得到的连接我已经写了代码来获取数据库字符串。在Inert方法中,我使用以下代码将值插入EMP表:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]

public class WebService1 : System.Web.Services.WebService 
{
    SqlConnection con;
    SqlCommand cmd;
    SqlDataReader sdr;

    public string name
    {
        set
        {
            name = value;
        }
        get
        {
            return name;
        }
    }
    public string dept
    {
        set
        {
            dept = value;
        }
        get
        {
            return dept;
        }
    }
    public string adress
    {
        set
        {
            adress = value;
        }
        get
        {
            return adress;
        }
    }
        public int salary
    {
        set
        {
            salary = value;
        }
        get
        {
            return salary;
        }

    }
        public string email
        {
            set
            {
                email = value;
            }
            get
            {
                return email;
            }

        }
    public WebService1()
    {
        //
        // TODO: Add any constructor code required
        //
    }

    // WEB SERVICE EXAMPLE
    // The HelloWorld() example service returns the string Hello World.

    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }
    [WebMethod]
    public void GetConnection()
    {
        string c = "Data Source=navse-win81_1;Initial Catalog=TestDatabase;Integrated Security=True;Pooling=False";
        con = new SqlConnection(c);
    }
    [WebMethod]
    public int Insert(Test obj)
    {


        GetConnection();
        string query = "insert into Emp(Name,Dept,Salary,Addres,Email)values(@na,@Dt,@sa,@ad,@em)";
        cmd = new SqlCommand(query, con);
        cmd.Parameters.AddWithValue("@na", obj.name);
        cmd.Parameters.AddWithValue("@dt", obj.dept);
        cmd.Parameters.AddWithValue("@sa", obj.salary);
        cmd.Parameters.AddWithValue("@ad", obj.adress);
        cmd.Parameters.AddWithValue("@em", obj.email);

        int a = cmd.ExecuteNonQuery();

        return a;
    }
}

public class Test:System.Web.Services.WebService
{

    public string name
    {
        set
        {
            name = value;
        }
        get
        {
            return name;
        }
    }
    public string dept
    {
        set
        {
            dept = value;
        }
        get
        {
            return dept;
        }
    }
    public string adress
    {
        set
        {
            adress = value;
        }
        get
        {
            return adress;
        }
    }
    public int salary
    {
        set
        {
            salary = value;
        }
        get
        {
            return salary;
        }

    }
    public string email
    {
        set
        {
            email = value;
        }
        get
        {
            return email;
        }

    }
}

When i am trying to access this web service in web browser getting following error: 当我尝试在Web浏览器中访问此Web服务时出现以下错误:

Server Error in '/Projects' Application.

Cannot serialize member System.ComponentModel.MarshalByValueComponent.Site of type System.ComponentModel.ISite because it is an interface. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.NotSupportedException: Cannot serialize member System.ComponentModel.MarshalByValueComponent.Site of type System.ComponentModel.ISite because it is an interface.

Source Error: 


 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 

[NotSupportedException: Cannot serialize member System.ComponentModel.MarshalByValueComponent.Site of type System.ComponentModel.ISite because it is an interface.]

[InvalidOperationException: Cannot serialize member 'System.ComponentModel.MarshalByValueComponent.Site' of type 'System.ComponentModel.ISite', see inner exception for more details.]
   System.Xml.Serialization.StructModel.CheckSupportedMember(TypeDesc typeDesc, MemberInfo member, Type type) +5640106
   System.Xml.Serialization.StructModel.GetPropertyModel(PropertyInfo propertyInfo) +122
   System.Xml.Serialization.StructModel.GetFieldModel(MemberInfo memberInfo) +89
   System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter) +247
   System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter) +378
   System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter) +5641243
   System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter) +378
   System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter) +5641243
   System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter) +378
   System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter) +1734

[InvalidOperationException: There was an error reflecting type 'Test'.]
   System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter) +1852
   System.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping(MemberMapping accessor, FieldModel model, XmlAttributes a, String ns, Type choiceIdentifierType, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +5648048
   System.Xml.Serialization.XmlReflectionImporter.ImportMemberMapping(XmlReflectionMember xmlReflectionMember, String ns, XmlReflectionMember[] xmlReflectionMembers, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +869
   System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +286

[InvalidOperationException: There was an error reflecting 'obj'.]
   System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +899
   System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(String elementName, String ns, XmlReflectionMember[] members, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, XmlMappingAccess access) +133
   System.Web.Services.Protocols.SoapReflector.ImportMembersMapping(XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, Boolean serviceDefaultIsEncoded, Boolean rpc, SoapBindingUse use, SoapParameterStyle paramStyle, String elementName, String elementNamespace, Boolean nsIsDefault, XmlReflectionMember[] members, Boolean validate, Boolean openModel, String key, Boolean writeAccess) +233
   System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo methodInfo, Boolean client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, String defaultNs) +1965

[InvalidOperationException: Method WebService1.Insert can not be reflected.]
   System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo methodInfo, Boolean client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, String defaultNs) +6262
   System.Web.Services.Description.SoapProtocolReflector.ReflectMethod() +137
   System.Web.Services.Description.ProtocolReflector.ReflectBinding(ReflectedBinding reflectedBinding) +1577
   System.Web.Services.Description.ProtocolReflector.Reflect() +641
   System.Web.Services.Description.ServiceDescriptionReflector.ReflectInternal(ProtocolReflector[] reflectors) +559
   System.Web.Services.Description.ServiceDescriptionReflector.Reflect(Type type, String url) +109
   System.Web.Services.Protocols.DocumentationServerType..ctor(Type type, String uri, Boolean excludeSchemeHostPortFromCachingKey) +230
   System.Web.Services.Protocols.DocumentationServerProtocol.Initialize() +472
   System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) +122

[InvalidOperationException: Unable to handle request.]
   System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) +325
   System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +171

[InvalidOperationException: Failed to handle request.]
   System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +346
   System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +209
   System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +47
   System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +226
   System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +145

       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34248  

Please suggest me if i am missing something here. 如果我在这里想念什么,请建议我。

Your public int Insert(Test obj) is decorated as web service method. 您的public int Insert(Test obj)被修饰为Web服务方法。 Later you can see that Test inherits from System.Web.Services.WebService . 稍后您将看到Test继承自System.Web.Services.WebService All webservice methods/objects (in this case input parameter Test ) should be xml-serializable; 所有Web服务方法/对象(在本例中为输入参数Test )都应该是xml可序列化的; best practice is to use simple POCO classes, that expose just the fields you should expose; 最佳实践是使用简单的POCO类,该类仅公开您应公开的字段; definitely not complex objects like all inherited stuff from WebService . 绝对不像所有从WebService继承的东西那样复杂的对象。 So my advise - drop the inheritance between Test and System.Web.Services.WebService . 所以我的建议-删除TestSystem.Web.Services.WebService之间的继承。

Like: 喜欢:

public class Test {
 ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Web服务应用程序中无法序列化System.ComponentModel.ISite类型的成员System.ComponentModel.MarshalByValueComponent.Site错误 - Can not Serializable member System.ComponentModel.MarshalByValueComponent.Site of type System.ComponentModel.ISite error in Web Service Application 无法序列化System.ComponentModel.ISite类型的成员 - Cannot serialize member of type System.ComponentModel.ISite 在模块中找不到类型system.componentmodel.marshalbyvaluecomponent - cannot find type system.componentmodel.marshalbyvaluecomponent in module 不实现接口成员'System.ComponentModel.INotifyPropertyChanged.PropertyChanged' - Does not implement interface member 'System.ComponentModel.INotifyPropertyChanged.PropertyChanged' 使用System.ComponentModel - Working with System.ComponentModel System.ComponentModel.BackgroundWorker - System.ComponentModel.BackgroundWorker 没有行号的错误在模块System.dll中找不到类型System.ComponentModel.TypeDescriptionProvider - Error with no line number Cannot find type System.ComponentModel.TypeDescriptionProvider in module System.dll 在Windows Phone 8.1模块System.dll中找不到类型System.ComponentModel.TypeConverter - Cannot find type System.ComponentModel.TypeConverter in module System.dll, Windows Phone 8.1 System.ComponentModel.InotifyPropertyChanging错误 - System.ComponentModel.InotifyPropertyChanging error 找不到System.ComponentModel.DataAnnotations - System.ComponentModel.DataAnnotations was not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM