WebService简单示例

简介: 记录一下,以备后用:代码using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.

记录一下,以备后用:

img_405b18b4b6584ae338e0f6ecaf736533.gif 代码
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引用后,下面是提取示例:

img_405b18b4b6584ae338e0f6ecaf736533.gif 代码
            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();

 

 

目录
相关文章
|
文件存储
PB调用WebService示例(含源码)
说起PowerBuilder,可能大家都会嗤之以鼻,然后说一句:“哥们,还用呢啊”?记得以前看过的电影“功夫熊猫“里说:存在即是合理。我想说得是,世界上如果这个东西或这件事情存在,一定有它的道理,好像扯得有些远啊。
1482 0
|
1月前
|
XML 数据格式
AXios接受XML格式的webservice并解析成数据格式
AXios接受XML格式的webservice并解析成数据格式
25 2
|
Web App开发 程序员 API
C# web api 返回类型设置为json的两种方法
每次写博客,第一句话都是这样的:程序员很苦逼,除了会写程序,还得会写博客!当然,希望将来的一天,某位老板看到此博客,给你的程序员职工加点薪资吧!因为程序员的世界除了苦逼就是沉默。我眼中的程序员大多都不爱说话,默默承受着编程的巨大压力,除了技术上的交流外,他们不愿意也不擅长和别人交流,更不乐意任何人走进他们的内心!    悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来。
2228 0
|
XML Web App开发 JSON
webapi的返回类型,webapi返回图片
原文:webapi的返回类型,webapi返回图片 1.0 首先是返回常用的系统类型,当然这些返回方式不常用到。如:int,string,list,array等。这些类型直接返回即可。 1 public List Get() 2 { 3 List list = new List() { "11","22","33"}; 4 return list; 5 } 1.1 用不同的浏览器测试发现,返回的类型竟然是不一样的。
1215 0
|
XML 数据格式 网络架构
httpclent调用webservice
httpclent调用 webservice   wsdl后缀服务 1.jar包: commons-logging-1.
1509 0