写了个web服务 结果在运行的时候出现 无法序列化接口 ITest请教解决方案 谢谢~

解决方案 »

  1.   


    接口的实现类已经支持了序列化 
     我在类前面加了
        [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;
            }    }
      

  2.   

    你的ITest 接口里面有没有引用其他不可序列化的对象?
      

  3.   

    错误堆栈信息:
    [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
     
      

  4.   

    类名前加上[Serializable] 你的类还要符合Serializable的规则,到MSDN上看看吧;