加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在webservice 中使用ArrayList 对象.

发布时间:2020-12-17 02:59:31 所属栏目:安全 来源:网络整理
导读:经常看到有人在网上问,如何使用WebService中使用ArrayList.其实这是因为没有好好看MSDN的原因. ArrayList 是一个线性列表对象(它还是有点意思的.),不过WebService不支持其,不是标准变量对象,如果要有WebService中使用得加上属性.??[XmlRoot("根元名")] 例: _

经常看到有人在网上问,如何使用WebService中使用ArrayList.其实这是因为没有好好看MSDN的原因.

ArrayList 是一个线性列表对象(它还是有点意思的.),不过WebService不支持其,不是标准变量对象,如果要有WebService中使用得加上属性.??[XmlRoot("根元名")]

例:

______________________序列化的类 YouClass.cs

using System;
using System.Xml.Serialization;

namespace SomeNS

{
?[Serializable]
?[XmlRoot("NewYouClass")]???? //该属性需要加上 xml根元的序列化
?public class YouSerializabledClass
?{
??private long m_lID;


???public YouSerializabledClass()
??{
??}
??public long lID
??{
???get
???{
????return m_lID;
???}
???set
???{
????m_lID=value;
???}
??}

}

______________________________操作YouClass的类 A.cs

[XmlInclude(typeof(YouSerializabledClass))]
??public YouSerializabledClass YouSerializabledClassOperation(Some?Var)
??{
????YouSerializabledClass.lID=Convert.ToInt64(Var);
? ???return YouSerializabledClass;
??}

_______________________ WebMethod

[WebMethod]
??[XmlInclude(typeof(YouSerializabledClass))]
??public? YouSerializabledClass YouWebMetho(SomeVar Var)
??{
???YouSerializabledClass YouSerializabledClass1=A.YouSerializabledClassOperation(Var);
???return YouSerializabledClass ;
??} 这样完了之后,将在客户端产生序列化类的影射.

_________________________________客户端的Reference.cs

//------------------------------------------------------------------------------
// <autogenerated>
//???? This code was generated by a tool.
//???? Runtime Version: 1.1.4322.573
//
//???? Changes to this file may cause incorrect behavior and will be lost if
//???? the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------

//
// 此源代码是由 Microsoft.VSDesigner 1.1.4322.573 版自动生成。
//
namespace SomeNS.SomeNSReference {
??? using System.Diagnostics;
??? using System.Xml.Serialization;
??? using System;
??? using System.Web.Services.Protocols;
??? using System.ComponentModel;
??? using System.Web.Services;
????
????
? [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/BeginYouWebMetho",RequestNamespace="http://tempuri.org/",ResponseNamespace="http://tempuri.org/",Use=System.Web.Services.Description.SoapBindingUse.Literal,ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
??????? [return: System.Xml.Serialization.XmlElementAttribute("NewYouClass",IsNullable=true)]
??????? public YouSerializabledClass YouWebMetho(string EPID) {
??????????? object[] results = this.Invoke("YouWebMetho",new object[] {
??????????????????????? EPID});
??????????? return ((YouSerializabledClass )(results[0]));
??????? }
???????
??????? /// <remarks/>
??????? public System.IAsyncResult BeginYouWebMetho(SomeVar Var,System.AsyncCallback callback,object asyncState) {
??????????? return this.BeginInvoke("BeginYouWebMetho",new object[] {
??????????????????????? Var},callback,asyncState);
??????? }
???????
??????? /// <remarks/>
??????? public YouSerializabledClass EndGetYouWebMetho(System.IAsyncResult asyncResult) {
??????????? object[] results = this.EndInvoke(asyncResult);
??????????? return ((YouSerializabledClass )(results[0]));
??????? }

?????????????????????
??????? /// <remarks/>
??? [System.Xml.Serialization.XmlTypeAttribute(Namespace="
http://tempuri.org/")]
??? public class YouSerializabledClass
{??????? ??????? /// <remarks/>??????? public long lID;?????? } 这就是你产生的序列化类.???????}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读