WebServiceの簡単な例
2451 ワード
後で使用するために記録します.
Webリファレンスを追加したら、抽出例を次に示します.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace Niunan.ZZ.JKDA.Web.webservice
{
/// <summary>
/// GGService
/// </summary>
[WebService(Namespace = "http://gxbest.cn/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// ASP.NET AJAX Web , 。
// [System.Web.Script.Services.ScriptService]
public class GGService : System.Web.Services.WebService
{
public Credentials token;
/// <summary>
///
/// </summary>
/// <returns></returns>
[WebMethod(Description = " ")]
[SoapHeader("token", Direction = SoapHeaderDirection.In)]
public List<Niunan.ZZ.JKDA.Model.S_GongGao> GetGongGao() {
if (token.AccountID != "admin" || token.PIN != "admin")
{
return null;
}
return new Niunan.ZZ.JKDA.DAL.S_GongGaoDAO().GetListArray("");
}
/// <summary>
/// web service
/// </summary>
public class Credentials : System.Web.Services.Protocols.SoapHeader
{
public string AccountID;
public string PIN;
}
}
}
Webリファレンスを追加したら、抽出例を次に示します.
cn.gxbest.GGService ws = new Niunan.ZZ.JKDA.Web.cn.gxbest.GGService();
ws.CredentialsValue = new Niunan.ZZ.JKDA.Web.cn.gxbest.Credentials() { AccountID = "admin", PIN = "admin" };
cn.gxbest.S_GongGao[] gg = ws.GetGongGao();
List<cn.gxbest.S_GongGao> list = new List<cn.gxbest.S_GongGao>();
foreach (cn.gxbest.S_GongGao item in gg)
{
list.Add(item);
}
GridView1.DataSource = list;
GridView1.DataBind();