Você está na página 1de 2

Now we are going to create a Web Service and Access it without using .NET IDE. STEPS: 1. Create .

asmx file in NOTEPAD -> TEST IT USING BROWSER LIKE.... http://localhost/testweb.asmx 2. Create a proxy for you .asmx file using WSDL utility from .NET command prompt. Start-Programs-VS.NET 2003-VS.NET Tools-VS.NET Command prompt create a directory named bin , prompt> md bin (c://winnt//temp) prompt: >
wsdl /l:cs /n:wservice /out:bin/testweb.cs http://localhost/testweb.asmx?WSDL

/l: represents language to produce output, /n: means namespace, /out: to store output This will create, a sourcefile named testweb.cs with a namespace wservice for reference. 3. Create a dll file from the .cs to access at run time from your client. prompt > csc /t:library /out:bin\testweb.dll bin\testweb.cs csc -- csharp compiler /t -- target file is a library file means .dll /out -- to store output 4. Create your web service client inlcude the namespace and call the service.

testweb.asmx --> Web Service _____________


<%@ WebService Language="C#" Class="testweb" %> using System; using System.Data; using System.Data.OleDb; using System.Web.Services; public class testweb : WebService { [WebMethod] public DataSet show () { OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\winnt\\temp\\db1.mdb");

OleDbDataAdapter da = new OleDbDataAdapter("select * from Table1", con); DataSet DS = new DataSet(); da.Fill(DS); return DS; con.Close(); con = null; } }

testwebclient.aspx --> Web Service Client ___________________________________


<%@ Page Language="C#" Explicit="true" Strict="true" Buffer="true"%> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <%@ Import Namespace="wservice" %> <html> <script language="C#" runat="server"> void Page_Load(Object sender, EventArgs e) { testweb obj = new testweb(); DataSet MyData = obj.show(); MyDataGrid.DataSource = MyData.Tables[0].DefaultView; MyDataGrid.DataBind(); } </script> <form runat="server"> <ASP:DataGrid id="MyDataGrid" runat="server" /> </form> </body> </html>

Você também pode gostar