我如何从ASMX Web服务返回用户定义的对象
作者:互联网
[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
编辑:Google将例外消息翻译为以下内容:
> MUHENDIS.Service1.engineer不能序列化无参数构造函数.
>’getItemResult’以反映发生的错误.
解决方法:
您需要确保工程师类标记为可序列化.
[Serializable]
public class engineer{ ....
标签:asmx,web-services,c,object 来源: https://codeday.me/bug/20191030/1970106.html