C# 使用c将序列化对象传递给.asmx中的webmethod#
从我的aspx.cs(codebehind)中,我正在使用webmethod(.asmx) 现在,我尝试将一个GUID作为对象从codebehind传递给webmethod。 我无法直接执行此操作,因为它会导致以下错误: 使用xmlclude或SoapInclude属性指定静态未知的类型。 所以,我尝试创建一个类C# 使用c将序列化对象传递给.asmx中的webmethod#,c#,asp.net,web-services,asmx,C#,Asp.net,Web Services,Asmx,从我的aspx.cs(codebehind)中,我正在使用webmethod(.asmx) 现在,我尝试将一个GUID作为对象从codebehind传递给webmethod。 我无法直接执行此操作,因为它会导致以下错误: 使用xmlclude或SoapInclude属性指定静态未知的类型。 所以,我尝试创建一个类 [Serializable] public class Key { public Guid _key; public Guid Key { g
[Serializable]
public class Key
{
public Guid _key;
public Guid Key
{
get
{
return _key;
}
set
{
_key = new Guid(ConfigurationManager.AppSettings["key"]);
}
}
}
public object AuthKey()
{
Key obj = new Key();
return obj;
}
//Calling the webservice like this,
get_list_webservice.return_data objlist = get_list_webservice.GetList(AuthKey());
//WebMethod
public return_data get_list_webservice(object obj)
{
}
现在,我用它来传递给webmethod。但还是不起作用
这有什么问题?我理解在将对象发送到webmethod时应该序列化该对象。但我哪里做错了?在哪里使用XMLInclude?如果Web方法将
对象作为参数,那么您可以将任何内容作为参数传递。您需要告诉代码有哪些可能性:
[XmlInclude(typeof(System.Guid))]
public return_data get_list_webservice(object obj)
显示“传递”GUID的代码。另外,您是否知道ASMX是旧技术?而且,[Serializable]
未被XML序列化程序使用。@JohnSaunders更新了代码。是的,我知道旧技术。但别无选择,现在开始使用它:(GetList
方法的签名是什么?参数的类型是什么?对象
或Guid
?@johnsaunds GetList方法使用一个类,该类将结果作为对象返回。请参阅上面的代码(再次更新).return_data是我使用的一个类,它包含作为其成员的结果和状态获取此错误:错误106属性“XmlInclude”在此声明类型上无效。它仅在“class、struct、method、interface”声明上有效。然后在方法上尝试。