跨平台调用asp.net WebService
要做一个asp.net WebService接口,客户端可能是java、Delphi程序,存在的问题是在客户端类无法序列化,方法调用也存在一些问题,但是经过测试在.net开发环境中应用该webservice没问题,可以正常调用.
解决的办法,在要暴露给客户端要序列化的类,要被远程调用的方法前加上一些Atrubuters
第一种是 .asmx文件的后台文件如 users.asmx.cs ,这里需要序列化类与方法
Code
[WebService(Namespace="http://kingonsoft.com/telehouse")]
[SoapRpcService(RoutingStyle=SoapServiceRoutingStyle.SoapAction)]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://kingonsoft.com/telehouse")]
[Serializable()]
public class TeleUser : System.Web.Services.WebService
{
[WebMethod]
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://127.0.0.1/getPersonInfo", RequestNamespace = "http://webservice.cmis.taiyang.com/", ResponseNamespace = "http://webservice.cmis.taiyang.com/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlArrayAttribute("return", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
[return: System.Xml.Serialization.XmlArrayItemAttribute("list", Namespace="http://com.taiyang.cmis.webservice.dto.MemberList")]
Member[] getPersonInfo([System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string bookno, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string @operator);}
[WebService(Namespace="http://kingonsoft.com/telehouse")]
[SoapRpcService(RoutingStyle=SoapServiceRoutingStyle.SoapAction)]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://kingonsoft.com/telehouse")]
[Serializable()]
public class TeleUser : System.Web.Services.WebService
{
[WebMethod]
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://127.0.0.1/getPersonInfo", RequestNamespace = "http://webservice.cmis.taiyang.com/", ResponseNamespace = "http://webservice.cmis.taiyang.com/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlArrayAttribute("return", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
[return: System.Xml.Serialization.XmlArrayItemAttribute("list", Namespace="http://com.taiyang.cmis.webservice.dto.MemberList")]
Member[] getPersonInfo([System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string bookno, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string @operator);}
第二种情况是 需要被序列化的普通实体类
i: 如果类的内部属性只是简单数据类型,序列化方法如下
Code
/**//// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://com.taiyang.cmis.webservice.dto.Member")]
public partial class Member
{
private string memberNOField;
private string nameField;
/**//// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string memberNO
{
get
{
return this.memberNOField;
}
set
{
this.memberNOField = value;
}
}
/**//// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
}
}
}
/**//// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://com.taiyang.cmis.webservice.dto.Member")]
public partial class Member
{
private string memberNOField;
private string nameField;
/**//// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string memberNO
{
get
{
return this.memberNOField;
}
set
{
this.memberNOField = value;
}
}
/**//// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
}
}
}
ii:如果类的内部属性不只是简单的数据类型,比如包含有自定义的数据类型,如含有数组 Piont[] psInfo ,且定义了一个类索引器来访问类的私有字段 psInfo . 这样的情况序列化的办法是:
Code
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://61.23.210.8/UserInterface/")]
[Serializable()]
public class UserInfo
{
public UserInfo()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private point[] psInfo=new point[0];
private string areaCode="";
/**//**//**//// <summary>
/// 配件信息
/// </summary>
public point this[int index]
{
get
{
// if ( index < 0 || index > psInfo.Length -1 )
// {
// return null;
// }
return (point)psInfo[index];
}
set
{
if ( index <0 || index >psInfo.Length-1 )
{
return ;
}
psInfo[index]=value;
}
}
public point[] Point
{
get
{
return psInfo;
}
set
{
psInfo=value;
}
}
/**//**//**//// <summary>
/// 城市代码
/// </summary>
public string AreaCode
{
get{return areaCode;}
set{areaCode=value;}
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://61.23.210.8/UserInterface/")]
[Serializable()]
public class UserInfo
{
public UserInfo()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private point[] psInfo=new point[0];
private string areaCode="";
/**//**//**//// <summary>
/// 配件信息
/// </summary>
public point this[int index]
{
get
{
// if ( index < 0 || index > psInfo.Length -1 )
// {
// return null;
// }
return (point)psInfo[index];
}
set
{
if ( index <0 || index >psInfo.Length-1 )
{
return ;
}
psInfo[index]=value;
}
}
public point[] Point
{
get
{
return psInfo;
}
set
{
psInfo=value;
}
}
/**//**//**//// <summary>
/// 城市代码
/// </summary>
public string AreaCode
{
get{return areaCode;}
set{areaCode=value;}
}
}
第三种情况 普通的业务逻辑类的序列化
Code
[System.SerializableAttribute()]
public class Users
{
public state Delete(userInfo obj)
{
//..
}
}
[System.SerializableAttribute()]
public class Users
{
public state Delete(userInfo obj)
{
//..
}
}