3
    [WebMethod]
    public engineer getItem()
    {
        DataClasses1DataContext db = new DataClasses1DataContext();
        List<string> list = new List<string>();
        string tcNo="13609224456";
        var bilgiler = db.bilgilers.First(c => c.tc_kimlik_no ==tcNo);

        string adi = bilgiler.adi;
        string soyadi = bilgiler.soyadi;
        string universite = bilgiler.universite;
        engineer e = new engineer(tcNo, adi, soyadi, universite);

        return e;
    }

我有不止一种方法,我可以无错误地运行 web 服务,但是当我调用该getItem()方法时,我得到以下异常。我该如何解决这个问题?

[InvalidOperationException: Parametresiz oluşturucusu olmadığından MUHENDIS.Service1.engineer seri hale getirilemez.]
   System.Xml.Serialization.TypeDesc.CheckSupported() +3938411
   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, RecursionLimiter limiter) +65
   System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +236

[InvalidOperationException: 'getItemResult' yansıtmada bir hata oluştu.]
   System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +843
   System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(String elementName, String ns, XmlReflectionMember[] members, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, XmlMappingAccess access) +130
   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) +223
   System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo methodInfo, Boolean client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, String defaultNs) +2989

编辑:谷歌将异常消息翻译如下:

  1. MUHENDIS.Service1.engineer 不是无参数的构造函数被序列化。
  2. 'getItemResult' 以反映发生的错误。
4

2 回答 2

3

您需要确保您的工程师类被标记为可序列化。

[Serializable]
public class engineer{ ....
于 2013-06-27T13:06:42.813 回答
1

我认为,您需要像这样定义 getItem 方法。

[WebMethod]
[XmlInclude(typeof(engineer))]
public engineer getItem(){
//codes here
}
//engineer class here

如果没有 XmlInclude 属性,XmlSerializer 将无法序列化工程师

于 2013-06-27T11:35:57.550 回答