Shoppingsservices.asmx

 

This is a separate web services module.The form shown above is what is called as  “Consuming a web service”. This form over here checks the status of the order given the email address and a order ID. This would give a DataGrid which gives the orderdate and shipped date along with it.

 

Now let us see from where is this consuming the webservice.

 

The file with the extension .asmx provides the webservice. Here I have made a file called as shoppingservice.asmx .To create a webservice just click on add a new web service.it will automatically add a new asmx file for u with refrences.If u have provided a successful webservice th u can reference this service from any solution. Lets go into the details.

 

The source code for the asmx file is

 

[WebMethod(Description="This method checks your status")]

              public DataTable CheckStatus(string emailaddress,int orderid)

              {

                     int id=0;

                     SqlConnection objcon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

                     string sql ="Select customerid from employees where emailaddress ='" + emailaddress +"'";

                     SqlCommand objcom = new SqlCommand(sql,objcon);

                     objcon.Open();

                     SqlDataReader objread= objcom.ExecuteReader(); // Returns a single result.

 

                     while(objread.Read())

                     {

                             id = objread.GetInt32(0);

                     }

 

                     if(Convert.ToInt32(id) == 0)

                     {

                           throw new Exception("Invalid email address");

                     }

                     objread.Close();

                    

                     string sql2="Select pr.modelname,Convert(char(10),coo.orderdate,110)orderdate,Convert(char(10),coo.shipdate,110)shipdate,od.quantity,od.unitcost,subtotal=od.quantity * od.unitcost from checkoutorders coo,orderdetails od,products pr where pr.productid =od.productid  and coo.orderid = od.orderid and coo.customerid ='" + id +"' and od.orderid ='" + orderid +"'";

                     SqlDataAdapter objda= new SqlDataAdapter(sql2,objcon);

                     DataTable dt = new DataTable();

                     objda.Fill(dt);

                     return dt; // Returns a datatable containing model name...

              }

 

 

 

This is a webservice method.Now to acess the method just add this as references to any solution.Like here what I have done is add a new web reference to the solution and given it a name called as ShoppingServices. We add this so that we can take an instance from that and access the method.

 

 

Back to main page