WebService简单示例
生活随笔
收集整理的這篇文章主要介紹了
WebService简单示例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
記錄一下,以備后用:
代碼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();
?
?
轉載于:https://www.cnblogs.com/niunan/archive/2010/08/03/1791525.html
總結
以上是生活随笔為你收集整理的WebService简单示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 线上问题随笔记录数据库连接池问题
- 下一篇: php 常用函数