Hello Error with Web Services. No se puede serializar el miembro System.ComponentModel.MarshalByValu

  • Thread starter Luis Esteban Valencia
  • Start date
L

Luis Esteban Valencia

Hello I have a solution iwth a web project and web service project I made a
project and I compiled it and it has no errors. But when I try to add the
web reference in the webproject I have this error.

The code of the WebService is this:
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;

namespace wsPortalProveedores

{

/// <summary>

/// Descripción breve de WSProveedores.

/// </summary>

public class WSProveedores : System.Web.Services.WebService

{

public WSProveedores()

{

//CODEGEN: llamada necesaria para el Diseñador de servicios Web ASP .NET

InitializeComponent();

}

private System.Data.SqlClient.SqlConnection conexion;

#region Código generado por el Diseñador de componentes


//Requerido por el Diseñador de servicios Web

private IContainer components = null;


/// <summary>

/// Método necesario para admitir el Diseñador. No se puede modificar

/// el contenido del método con el editor de código.

/// </summary>

private void InitializeComponent()

{

System.Configuration.AppSettingsReader configurationAppSettings = new
System.Configuration.AppSettingsReader();

this.conexion = new System.Data.SqlClient.SqlConnection();

//

// conexion

//

this.conexion.ConnectionString =
((string)(configurationAppSettings.GetValue("Conexion1", typeof(string))));

}

/// <summary>

/// Limpiar los recursos que se estén utilizando.

/// </summary>

protected override void Dispose( bool disposing )

{

if(disposing && components != null)

{

components.Dispose();

}

base.Dispose(disposing);

}


#endregion

// EJEMPLO DE SERVICIO WEB

// El servicio de ejemplo HelloWorld() devuelve la cadena Hola a todos

// Para generar, quite la marca de comentario de las siguientes líneas y,
después, guarde y genere el proyecto

// Para probar el servicio Web, presione F5

// [WebMethod]

// public string HelloWorld()

// {

// return "Hola a todos";

// }

[WebMethod]

public bool verificar(string usuario, string password)

{

System.Configuration.AppSettingsReader configurationAppSettings = new
System.Configuration.AppSettingsReader();

conexion.ConnectionString =
((string)(configurationAppSettings.GetValue("Conexion", typeof(string))));

SqlCommand mycmd = new SqlCommand();

mycmd.CommandText = "autenticar";

mycmd.Connection = conexion;

mycmd.CommandType = CommandType.StoredProcedure;

SqlParameter param1 = new SqlParameter();

SqlParameter param2 = new SqlParameter();

param1.Direction = ParameterDirection.Input;

param2.Direction = ParameterDirection.Input;

mycmd.Parameters.Add("@UID", usuario);

mycmd.Parameters.Add("@password", password);

conexion.Open();

SqlDataReader myreader = mycmd.ExecuteReader();

try

{

myreader.Read();

if(myreader.HasRows)

{

return true;

}

else

{

return false;

}

}

catch(Exception ex)

{

throw ex;

}

finally

{

conexion.Close();

}

}

[WebMethod]

public DataTable Proveedorenstock(string usuario)

{

SqlDataAdapter sqladp = new SqlDataAdapter("paproveedores1", conexion);

sqladp.SelectCommand.CommandType = CommandType.StoredProcedure;

sqladp.SelectCommand.Parameters.Add("@proveedor", usuario);

conexion.Open();

try

{

DataSet ds = new DataSet();

sqladp.Fill(ds, "Proveedoresenstock");

return ds.Tables["Proveedoresenstock"];

}

catch(Exception ex)

{

throw ex;

}

finally

{

conexion.Close();

}


}

}

}



Error de servidor en la aplicación '/wsPortalProveedores'.
----------------------------------------------------------------------------
----

No se puede serializar el miembro
System.ComponentModel.MarshalByValueComponent.Site de tipo
System.ComponentModel.ISite porque es una interfaz.
Descripción: Excepción no controlada al ejecutar la solicitud Web actual.
Revise el seguimiento de la pila para obtener más información acerca del
error y dónde se originó en el código.

Detalles de la excepción: System.NotSupportedException: No se puede
serializar el miembro System.ComponentModel.MarshalByValueComponent.Site de
tipo System.ComponentModel.ISite porque es una interfaz.

Error de código fuente:

Se ha generado una excepción no controlada durante la ejecución de la
solicitud Web actual. La información sobre el origen y la ubicación de la
excepción pueden identificarse utilizando la excepción del seguimiento de la
pila siguiente.

Seguimiento de la pila:

[NotSupportedException: No se puede serializar el miembro
System.ComponentModel.MarshalByValueComponent.Site de tipo
System.ComponentModel.ISite porque es una interfaz.]
System.Xml.Serialization.TypeScope.ImportTypeDesc(Type type, Boolean
canBePrimitive, MemberInfo memberInfo) +1283
System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo
source, Boolean directReference) +50
System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo
source)
System.Xml.Serialization.StructModel.GetPropertyModel(PropertyInfo
propertyInfo)
System.Xml.Serialization.StructModel.GetFieldModel(MemberInfo memberInfo)

System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(Struc
tModel model, String ns)

System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(Struc
tModel model, String ns)

System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel
model, String ns, ImportContext context, String dataType, Boolean repeats)
+440

[InvalidOperationException: Error al reflejar el tipo
'System.Data.DataTable'.]

System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel
model, String ns, ImportContext context, String dataType, Boolean repeats)
+1059

System.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping(MemberM
apping accessor, FieldModel model, XmlAttributes a, String ns, Type
choiceIdentifierType) +8242

System.Xml.Serialization.XmlReflectionImporter.ImportMemberMapping(XmlReflec
tionMember xmlReflectionMember, String ns, XmlReflectionMember[]
xmlReflectionMembers) +795

System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlRefle
ctionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement)
+300

[InvalidOperationException: Error al reflejar 'ProveedorenstockResult'.]

System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlRefle
ctionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement)
+607

System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(String
elementName, String ns, XmlReflectionMember[] members, Boolean
hasWrapperElement) +108

System.Web.Services.Protocols.SoapReflector.ImportMembersMapping(XmlReflecti
onImporter xmlImporter, SoapReflectionImporter soapImporter, Boolean
serviceDefaultIsEncoded, Boolean rpc, SoapBindingUse use, SoapParameterStyle
paramStyle, String elementName, String elementNamespace, Boolean
nsIsDefault, XmlReflectionMember[] members, Boolean validate) +169

System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo
methodInfo, Boolean client, XmlReflectionImporter xmlImporter,
SoapReflectionImporter soapImporter, String defaultNs) +2860

[InvalidOperationException: No se puede reflejar el método
WSProveedores.Proveedorenstock.]

System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo
methodInfo, Boolean client, XmlReflectionImporter xmlImporter,
SoapReflectionImporter soapImporter, String defaultNs) +5415
System.Web.Services.Description.SoapProtocolReflector.ReflectMethod()
+130

System.Web.Services.Description.ProtocolReflector.ReflectBinding(ReflectedBi
nding reflectedBinding) +1818
System.Web.Services.Description.ProtocolReflector.Reflect() +506

System.Web.Services.Description.ServiceDescriptionReflector.ReflectInternal(
ProtocolReflector[] reflectors) +495
System.Web.Services.Description.ServiceDescriptionReflector.Reflect(Type
type, String url) +112
System.Web.Services.Protocols.DocumentationServerType..ctor(Type type,
String uri) +158
System.Web.Services.Protocols.DocumentationServerProtocol.Initialize()
+269
System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type,
HttpContext context, HttpRequest request, HttpResponse response, Boolean&
abortProcessing) +106

[InvalidOperationException: No se puede administrar la solicitud.]
System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type,
HttpContext context, HttpRequest request, HttpResponse response, Boolean&
abortProcessing) +205

System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type
type, HttpContext context, HttpRequest request, HttpResponse response) +82

[InvalidOperationException: No se pudo administrar la solicitud.]

System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type
type, HttpContext context, HttpRequest request, HttpResponse response) +154

System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContex
t context, String verb, String url, String filePath) +94
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String
requestType, String path, String pathTranslated, Boolean useAppConfig) +699

System.Web.MapHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep
..Execute() +95
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +173
 
S

Sami Vaaraniemi

My Spanish (?) is really rusty but I think the problem is that you are
trying to return a DataTable from a web method. This will not work, you will
have to return a DataSet containing your DataTable instead. See
http://support.microsoft.com/default.aspx?scid=kb;en-us;306134.

Regards,
Sami

Luis Esteban Valencia said:
Hello I have a solution iwth a web project and web service project I made a
project and I compiled it and it has no errors. But when I try to add the
web reference in the webproject I have this error.

The code of the WebService is this:
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;

namespace wsPortalProveedores

{

/// <summary>

/// Descripción breve de WSProveedores.

/// </summary>

public class WSProveedores : System.Web.Services.WebService

{

public WSProveedores()

{

//CODEGEN: llamada necesaria para el Diseñador de servicios Web ASP .NET

InitializeComponent();

}

private System.Data.SqlClient.SqlConnection conexion;

#region Código generado por el Diseñador de componentes


//Requerido por el Diseñador de servicios Web

private IContainer components = null;


/// <summary>

/// Método necesario para admitir el Diseñador. No se puede modificar

/// el contenido del método con el editor de código.

/// </summary>

private void InitializeComponent()

{

System.Configuration.AppSettingsReader configurationAppSettings = new
System.Configuration.AppSettingsReader();

this.conexion = new System.Data.SqlClient.SqlConnection();

//

// conexion

//

this.conexion.ConnectionString =
((string)(configurationAppSettings.GetValue("Conexion1", typeof(string))));

}

/// <summary>

/// Limpiar los recursos que se estén utilizando.

/// </summary>

protected override void Dispose( bool disposing )

{

if(disposing && components != null)

{

components.Dispose();

}

base.Dispose(disposing);

}


#endregion

// EJEMPLO DE SERVICIO WEB

// El servicio de ejemplo HelloWorld() devuelve la cadena Hola a todos

// Para generar, quite la marca de comentario de las siguientes líneas y,
después, guarde y genere el proyecto

// Para probar el servicio Web, presione F5

// [WebMethod]

// public string HelloWorld()

// {

// return "Hola a todos";

// }

[WebMethod]

public bool verificar(string usuario, string password)

{

System.Configuration.AppSettingsReader configurationAppSettings = new
System.Configuration.AppSettingsReader();

conexion.ConnectionString =
((string)(configurationAppSettings.GetValue("Conexion", typeof(string))));

SqlCommand mycmd = new SqlCommand();

mycmd.CommandText = "autenticar";

mycmd.Connection = conexion;

mycmd.CommandType = CommandType.StoredProcedure;

SqlParameter param1 = new SqlParameter();

SqlParameter param2 = new SqlParameter();

param1.Direction = ParameterDirection.Input;

param2.Direction = ParameterDirection.Input;

mycmd.Parameters.Add("@UID", usuario);

mycmd.Parameters.Add("@password", password);

conexion.Open();

SqlDataReader myreader = mycmd.ExecuteReader();

try

{

myreader.Read();

if(myreader.HasRows)

{

return true;

}

else

{

return false;

}

}

catch(Exception ex)

{

throw ex;

}

finally

{

conexion.Close();

}

}

[WebMethod]

public DataTable Proveedorenstock(string usuario)

{

SqlDataAdapter sqladp = new SqlDataAdapter("paproveedores1", conexion);

sqladp.SelectCommand.CommandType = CommandType.StoredProcedure;

sqladp.SelectCommand.Parameters.Add("@proveedor", usuario);

conexion.Open();

try

{

DataSet ds = new DataSet();

sqladp.Fill(ds, "Proveedoresenstock");

return ds.Tables["Proveedoresenstock"];

}

catch(Exception ex)

{

throw ex;

}

finally

{

conexion.Close();

}


}

}

}



Error de servidor en la aplicación '/wsPortalProveedores'.
-------------------------------------------------------------------------- --
----

No se puede serializar el miembro
System.ComponentModel.MarshalByValueComponent.Site de tipo
System.ComponentModel.ISite porque es una interfaz.
Descripción: Excepción no controlada al ejecutar la solicitud Web actual.
Revise el seguimiento de la pila para obtener más información acerca del
error y dónde se originó en el código.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top