[WebMethod] public DataSet CustOrderHist(string CustId) { // 只接受 SOAP格式的请求 SoapContext requestContext = HttpSoapContext.RequestContext; if(requestContext==null) { throw new ApplicationException("Non-SOAP request!"); } bool valid=false; try { foreach(SecurityToken tkn in requestContext.Security.Tokens) { if(tkn is UsernameToken) valid=true; } } catch(Exception ex) { throw new Exception( ex.Message + ": " + ex.InnerException.Message); } if (valid==false) throw new ApplicationException("Invalid or Missing Security Token."); SqlConnection cn; SqlDataAdapter da; DataSet ds; cn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["SqlConn"].ToString()); cn.Open(); da = new SqlDataAdapter("custorderHist '" +CustId + "'", cn); ds = new DataSet(); da.Fill(ds, "CustOrderHist"); return ds; } |
private void Button1_Click(object sender, System.EventArgs e) { localhost.SecurityServiceWse wse=new localhost.SecurityServiceWse(); UsernameToken tkn = new UsernameToken(txtUsername.Text,txtPassword.Text,PasswordOption.SendHashed); wse.RequestSoapContext.Security.Tokens.Add (tkn); try { DataSet ds=wse.CustOrderHist(txtCustID.Text); DataGrid1.DataSource=ds; DataGrid1.DataBind(); } catch(Exception ex) { DataGrid1.Visible=false; lblMessages.Text=ex.Message; } } |
USE NORTHWIND GO ALTER TABLE [dbo].[Employees] ADD [Username] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [Password] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [roles] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL GO INSERT INTO EMPLOYEES (Firstname, Lastname,Username, [Password], roles) VALUES('User','One', 'user1', 'pass1', 'user') GO |