PRODID - int (Primary key) prodname - varchar(50) price - money qoh - int remarks - varchar(200) catcode - varchar(10)
using System; using System.Web.Services; using System.Runtime.Serialization; public class Product { private int prodid, qty; private string name, remarks; private double price; public int Qty { get { return qty; } set { qty = value; } } public int Prodid { get { return prodid; } set { prodid = value; } } public string Remarks { get { return remarks; } set { remarks = value; } } public string Name { get { return name; } set { name = value; } } public double Price { get { return price; } set { price = value; } } }
<connectionStrings> <add name="msdbcs" connectionString="data source=localhost\sqlexpress;integrated security=true;Initial Catalog=msdb" providerName="System.Data.SqlClient" /> </connectionStrings >
using System.Web.Configuration; public class Database { public static string ConnectionString { get { return WebConfigurationManager.ConnectionStrings["msdbcs"].ConnectionString; } } }
using System; using System.Data; using System.Data.SqlClient; using System.Collections.Generic; public class ProductsDAL { public static List GetAllProducts() { SqlConnection con = new SqlConnection(Database.ConnectionString); con.Open(); SqlCommand cmd = new SqlCommand("select * from products", con); SqlDataReader dr = cmd.ExecuteReader(); List products = new List(); while (dr.Read()) { Product p = new Product(); p.Prodid = (int)dr["prodid"]; p.Name = dr["prodname"].ToString(); p.Remarks = dr["remarks"].ToString(); p.Qty = (int)dr["qoh"]; p.Price = Convert.ToDouble(dr["price"]); products.Add(p); } dr.Close(); con.Close(); return products; } public static Product GetProduct(int prodid) { SqlConnection con = new SqlConnection(Database.ConnectionString); con.Open(); SqlCommand cmd = new SqlCommand("select * from products where prodid = @prodid", con); cmd.Parameters.AddWithValue("@prodid", prodid); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { Product p = new Product(); p.Prodid = (int) dr["prodid"]; p.Name = dr["prodname"].ToString(); p.Remarks = dr["remarks"].ToString(); p.Qty = (int) dr["qoh"]; p.Price = Convert.ToDouble (dr["price"]); return p; } else // product not found return null; } }
using System; using System.Web.Services; using System.Collections.Generic; [WebService(Namespace = "http://www.srikanthtechnologies.com/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class InventoryService : System.Web.Services.WebService { [WebMethod( Description ="Returns Details Of All Products")] public List GetAllProducts() { return ProductsDAL.GetAllProducts(); } [WebMethod(Description = "Returns Details Of A Single Product")] public Product GetProduct(int prodid) { return ProductsDAL.GetProduct(prodid); } }
<s:complexType name="ArrayOfProduct"> <s:sequence> <s:element minOccurs="0" maxOccurs="unbounded" name="Product" nillable="true" type="tns:Product" /> </s:sequence> </s:complexType> <s:complexType name="Product"> <s:sequence> <s:element minOccurs="1" maxOccurs="1" name="Qty" type="s:int" /> <s:element minOccurs="1" maxOccurs="1" name="Prodid" type="s:int" /> <s:element minOccurs="0" maxOccurs="1" name="Remarks" type="s:string" /> <s:element minOccurs="0" maxOccurs="1" name="Name" type="s:string" /> <s:element minOccurs="1" maxOccurs="1" name="Price" type="s:double" /> </s:sequence> </s:complexType>
try { // Call Web Service Operation com.srikanthtechnologies.InventoryService service = new com.srikanthtechnologies.InventoryService(); com.srikanthtechnologies.InventoryServiceSoap port = service.getInventoryServiceSoap12(); // TODO initialize WS operation arguments here int prodid = 100; // TODO process result here com.srikanthtechnologies.Product result = port.getProduct(prodid); System.out.println( result.getName()); } catch (Exception ex) { // TODO handle custom exceptions here }
try { // Call Web Service Operation com.srikanthtechnologies.InventoryService service = new com.srikanthtechnologies.InventoryService(); com.srikanthtechnologies.InventoryServiceSoap port = service.getInventoryServiceSoap12(); // TODO process result here com.srikanthtechnologies.ArrayOfProduct result = port.getAllProducts(); List products = result.getProduct(); for(Product p : products) { System.out.println( p.getName() + " : " + p.getPrice()); } } catch (Exception ex) { // TODO handle custom exceptions here }