如何写一个可以序列化的接口 谢谢~ 写了个web服务 结果在运行的时候出现 无法序列化接口 ITest请教解决方案 谢谢~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 接口的实现类已经支持了序列化 我在类前面加了 [Serializable()]这个申明了web服务中这么写的 [WebService ( Namespace = "test.test.test.test" )] [WebServiceBinding ( ConformsTo = WsiProfiles.BasicProfile1_1 )] [ToolboxItem ( false )] public class testService : System.Web.Services.WebService { [WebMethod] public bool Insert (ITest test,string typeName ) { ITestDAL testDAL = ReflectTestFactory.CreateTestByReflect ( typeName ); return testDAL.Insert ( test); } }接口: public interface ITest { }实现类:[Serializable()] public class T_JT_ZuanTouChengXu:IEntity { public int id { get; set; } public Decimal name { get; set; } } 你的ITest 接口里面有没有引用其他不可序列化的对象? 错误堆栈信息:[NotSupportedException: 无法序列化接口 Test。] System.Xml.Serialization.TypeDesc.CheckSupported() +871737 System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError) +170 System.Xml.Serialization.XmlReflectionImporter.ImportMemberMapping(XmlReflectionMember xmlReflectionMember, String ns, XmlReflectionMember[] xmlReflectionMembers, Boolean rpc, Boolean openModel) +78 System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement, Boolean rpc, Boolean openModel) +278[InvalidOperationException: 反射 "test”时出错。] System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement, Boolean rpc, Boolean openModel) +877 System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(String elementName, String ns, XmlReflectionMember[] members, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, XmlMappingAccess access) +111 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) +203 System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo methodInfo, Boolean client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, String defaultNs) +2460[InvalidOperationException: 无法反射方法 Service.Insert。] System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo methodInfo, Boolean client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, String defaultNs) +6904 System.Web.Services.Description.SoapProtocolReflector.ReflectMethod() +133 System.Web.Services.Description.ProtocolReflector.ReflectBinding(ReflectedBinding reflectedBinding) +2760 System.Web.Services.Description.ProtocolReflector.Reflect() +739 System.Web.Services.Description.ServiceDescriptionReflector.ReflectInternal(ProtocolReflector[] reflectors) +621 System.Web.Services.Description.ServiceDescriptionReflector.Reflect(Type type, String url) +117 System.Web.Services.Protocols.DocumentationServerType..ctor(Type type, String uri) +157 System.Web.Services.Protocols.DocumentationServerProtocol.Initialize() +336 System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) +105[InvalidOperationException: 无法处理请求。] System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) +295 System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +202[InvalidOperationException: 处理请求失败。] System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +363 System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +211 System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +145 System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +175 System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +128 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +161 类名前加上[Serializable] 你的类还要符合Serializable的规则,到MSDN上看看吧; C# WinForm中使用DevExpress DockManager控件问题 ?急急急 正则 udp操作时断开网络导致系统故障 能不能在一个类中使用另一个类的实例? 求gif动画生成缩略图 控件如何与二维数组绑定? 发送邮件程序错误:未能访问“CDO.Message”对象 大哥们快帮帮忙啊!!! DataGrid怎样才能重新写列名啊? C#知道升级教程——针对简单应用 C# WinForm 打包问题,急!!! 如何CATCH主键重复问题??
接口的实现类已经支持了序列化
我在类前面加了
[Serializable()]
这个申明了web服务中这么写的 [WebService ( Namespace = "test.test.test.test" )]
[WebServiceBinding ( ConformsTo = WsiProfiles.BasicProfile1_1 )]
[ToolboxItem ( false )]
public class testService : System.Web.Services.WebService
{ [WebMethod]
public bool Insert (ITest test,string typeName )
{
ITestDAL testDAL = ReflectTestFactory.CreateTestByReflect ( typeName );
return testDAL.Insert ( test);
}
}接口: public interface ITest
{ }实现类:[Serializable()]
public class T_JT_ZuanTouChengXu:IEntity
{
public int id
{
get;
set;
}
public Decimal name
{
get;
set;
} }
[NotSupportedException: 无法序列化接口 Test。]
System.Xml.Serialization.TypeDesc.CheckSupported() +871737
System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError) +170
System.Xml.Serialization.XmlReflectionImporter.ImportMemberMapping(XmlReflectionMember xmlReflectionMember, String ns, XmlReflectionMember[] xmlReflectionMembers, Boolean rpc, Boolean openModel) +78
System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement, Boolean rpc, Boolean openModel) +278[InvalidOperationException: 反射 "test”时出错。]
System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement, Boolean rpc, Boolean openModel) +877
System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(String elementName, String ns, XmlReflectionMember[] members, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, XmlMappingAccess access) +111
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) +203
System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo methodInfo, Boolean client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, String defaultNs) +2460
[InvalidOperationException: 无法反射方法 Service.Insert。]
System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo methodInfo, Boolean client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, String defaultNs) +6904
System.Web.Services.Description.SoapProtocolReflector.ReflectMethod() +133
System.Web.Services.Description.ProtocolReflector.ReflectBinding(ReflectedBinding reflectedBinding) +2760
System.Web.Services.Description.ProtocolReflector.Reflect() +739
System.Web.Services.Description.ServiceDescriptionReflector.ReflectInternal(ProtocolReflector[] reflectors) +621
System.Web.Services.Description.ServiceDescriptionReflector.Reflect(Type type, String url) +117
System.Web.Services.Protocols.DocumentationServerType..ctor(Type type, String uri) +157
System.Web.Services.Protocols.DocumentationServerProtocol.Initialize() +336
System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) +105[InvalidOperationException: 无法处理请求。]
System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) +295
System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +202[InvalidOperationException: 处理请求失败。]
System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +363
System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +211
System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +145
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +175
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +128
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +161