Web Service Creation:
I have created a service called "Student_service'in the local directory on my local machine. The files will be created in the Student_Service directory.
A new namespace will be defined called "Student_Service" and within this namespace will be a set of classes that define your Web Service.
By default the class Service1 is created in Service1.cs file, which is derived from System.Web.Services.WebService.
Within a class,a default method 'HelloWorld' is generated, we can simply comment the method and add userdefined method.
A WebService should be associated with a namespace. The Wizard-generated service will have the name space "http://tempuri.org". If you compile and run the service as-is you will get a long involved message indicating you should choose a new namespace, so we add the namespace, and the WebService description as follows:
[WebService(Namespace="http://codeproject.com/webservices/",
Description="This is a demonstration WebService.")]
public class Service1 : System.Web.Services.WebService
{
....
}
To test the service you can right click on Service1.asmx in the Solution Explorer in Visual Studio and choose "View in Browser" or simply build and run the webservice.
The page will be shown in the browser.
Steps for publishing the webservice:
Click Publish service from the build menu option.
specify the target location, where you want to publish the webservice.
Click Publish, The service will be published successfully.
Steps for adding the webservice to the IIS:
From the administartive tools or from the C:\WINDOWS\system32\inetsrv path open the inetmgr.exe
In left Pane,right-click on the Default Web Site, and select New and then Virtual Directory.
Click Next to begin the Wizard.
Enter the virtual directory name as the Alias.
Enter the path to the directory you are linking to(path where you publish the website).
Set the permissions for the virtual directory.
Click Finish.
Steps for adding the webservice reference to the website:
Open the Wesite, in which you want to use the webservice.
In the solution explorer, right click on website and select "Add Web Reference"
This displays the links, for the webservice on local computer.
Click on the "Web Services for the local machine link"
Click on the "service" link, where it navigates to the url, where the webservice methods are found.
On the right pane, it displays the Services found at that url, give the Webs reference name, and click "Add Reference".
Now the webservice is successfully added to the application.
For accessing the webservice methods in the application:
From vs2008 cmd prompt type wsdl http://localhost:4279/service1 (path)
creates the service1.cs file in c:/ProgramFiles.../Service1.cs.
cut the file "Service1.cs" from that location and add to the applicaton.
Now we can create the Object for the Webservice class, and access the webservice method.
Example: Service1 obj = new Service1();
Where SErvice1 is the default class in webservice.
I have created a service called "Student_service'in the local directory on my local machine. The files will be created in the Student_Service directory.
A new namespace will be defined called "Student_Service" and within this namespace will be a set of classes that define your Web Service.
By default the class Service1 is created in Service1.cs file, which is derived from System.Web.Services.WebService.
Within a class,a default method 'HelloWorld' is generated, we can simply comment the method and add userdefined method.
A WebService should be associated with a namespace. The Wizard-generated service will have the name space "http://tempuri.org". If you compile and run the service as-is you will get a long involved message indicating you should choose a new namespace, so we add the namespace, and the WebService description as follows:
[WebService(Namespace="http://codeproject.com/webservices/",
Description="This is a demonstration WebService.")]
public class Service1 : System.Web.Services.WebService
{
....
}
To test the service you can right click on Service1.asmx in the Solution Explorer in Visual Studio and choose "View in Browser" or simply build and run the webservice.
The page will be shown in the browser.
Steps for publishing the webservice:
Click Publish service from the build menu option.
specify the target location, where you want to publish the webservice.
Click Publish, The service will be published successfully.
Steps for adding the webservice to the IIS:
From the administartive tools or from the C:\WINDOWS\system32\inetsrv path open the inetmgr.exe
In left Pane,right-click on the Default Web Site, and select New and then Virtual Directory.
Click Next to begin the Wizard.
Enter the virtual directory name as the Alias.
Enter the path to the directory you are linking to(path where you publish the website).
Set the permissions for the virtual directory.
Click Finish.
Steps for adding the webservice reference to the website:
Open the Wesite, in which you want to use the webservice.
In the solution explorer, right click on website and select "Add Web Reference"
This displays the links, for the webservice on local computer.
Click on the "Web Services for the local machine link"
Click on the "service" link, where it navigates to the url, where the webservice methods are found.
On the right pane, it displays the Services found at that url, give the Webs reference name, and click "Add Reference".
Now the webservice is successfully added to the application.
For accessing the webservice methods in the application:
From vs2008 cmd prompt type wsdl http://localhost:4279/service1 (path)
creates the service1.cs file in c:/ProgramFiles.../Service1.cs.
cut the file "Service1.cs" from that location and add to the applicaton.
Now we can create the Object for the Webservice class, and access the webservice method.
Example: Service1 obj = new Service1();
Where SErvice1 is the default class in webservice.
No comments:
Post a Comment