sql2005建webservice及在vs2005中的应用

sql2005创建webservice

CREATE ENDPOINT mymusic 
state
=started 
as http( 
path
='/sql/music'
AUTHENTICATION
=(INTEGRATED), 
ports
=(clear) 

for soap( 
WebMethod 
'mymusic'(               
FORMAT
=ROWSETS_ONLY,
SCHEMA =STANDARD ,
name
='cm_text.dbo.getgs'             --cm_text为数据库名getgs为存储过程
), 
wsdl
=default
database='cm_text'
namespace
='http://mysite.org/'

vs2005中应用
首先进行WEB引用,此处为music
 1using System;
 2using System.Data;
 3using System.Configuration;
 4using System.Collections;
 5using System.Web;
 6using System.Web.Security;
 7using System.Web.UI;
 8using System.Web.UI.WebControls;
 9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11using music;
12using System.Net;
13using System.IO;
14using System.Text;
15
16public partial class Default2 : System.Web.UI.Page
17{
18    public ListBox catalogListBox;
19    public string ad="";
20    protected void Page_Load(object sender, EventArgs e)
21    {
22        Label1.Text=User.Identity.Name;
23        Label2.Text = User.Identity.AuthenticationType;
24        music.mymusic d = new mymusic();
25        CredentialCache a = new CredentialCache();
26        a.Add(new Uri("http://192.168.20.216"), "NTLM"new NetworkCredential("administrator""密码")); //此处用的是NTLM登陆方式
27        d.Credentials = a.GetCredential(new Uri("http://192.168.20.216"),"NTLM");
28        GridView1.DataSource = d.Callmymusic();
29        GridView1.DataBind();
30    }

31}

posted on 2006-05-17 16:57  苍冥  阅读(1015)  评论(0编辑  收藏  举报

导航