How to create the Web Services component in C#.NET
Hey Friends,
I have enough knowledge about the C#.NET so therefore i have decided to start with making web services component in the C#.Net, but I wanted to have a little helping hand about how to start for making the web services.
I have Visual Studio 2005 installed on my computer,So, If anyone aware about it please let me know.
Thanking you
Re: How to create the Web Services component in C#.NET
Web Services run on top of HTTP. Therefore, they are developed and deployed on a Web Server and their URL is advertised so that "Internet" clients can discover and make use of their services. Even though that Web Server can be Microsoft IIS, or Apache, or any other such server, at this point in time, the .NET framework only supports deployment on Microsoft IIS.
In this article, we will build a web service called OIDServer that clients can use to generate a unique Object Identity (OID) string. The generated OID string is unique, and can be used by the client wherever unique keys are needed - either for COM GUIDs, or to act as a unique primary key for a database table, etc. Since the Web Service class is deployed on a Web Server, any "Internet" client can access it and make use of its services - as opposed to COM components which can only be accessed by COM clients.
The various steps that are involved in creating a Web Service Component using C# and the .NET Framework are as follows (I'm going to assume you're using the VS.NET IDE):
- Create a Visual C# - ASP.NET Web Service project
- Develop the OIDServer.asmx file and the OIDServer.asmx.cs class file
- Modify the generated AssemblyInfo.cs to add the right assembly information
- Build the Project Files
you may get some more info here:
http://my.execpc.com/~gopalan/dotnet...ce_server.html
Re: How to create the Web Services component in C#.NET
We are going to use C# to create a Web Service called "SecurityWebService." A Web Service file will have an .ASMX file extension. (as opposed to an .ASPX file extension of a ASP.NET file). The first line of the file will look like
Code:
<%@ WebService Language="C#" class="SecurityWebService" %>
This line will instruct the compiler to run on Web Service mode and the name of the C# class. We also need to access the Web Service namespace. It is also a good practice to add a reference to the System namespace.
using System;
using System.Web.Services;
The SecurityWebService class should inherit the functionality of the Web Services class. Therefore, we put the following line of code:
public class SecurityWebService : WebService
Now we can use our object-oriented programming skills to build a class. C# classes are very similar to C++ or Java classes. It will be a walk in the park to create a C# class for anyone with either language-coding skills.
Dot-net Web Services are intelligent enough to cast basic data types. Therefore, if we return "int," "float," or "string" data types, it can convert them to standard XML output. Unfortunately, in most cases we need get a collection of data regarding a single entity. Let's take an example.
Our SecurityWebService stock quotes service requires the user to enter a company code, and it will deliver the full company name and the current stock price. Therefore, we have three pieces of information for a single company:
1. Company code (data type - string)
2. Company name (data type - string)
3. Price (data type - Double)
Re: How to create the Web Services component in C#.NET
IIS, create a virtual folder. Create a bin directory in the physical path of the virtual folder and copy the dll file in the bin folder.
Create a file TestService.asmx in the physical path of and paste the following code in it:
<%@ WebService Language="C#" Class="Service1" %>
using System.Web.Services;
public class Service1 : System.Web.Services.WebService { [WebMethod Description="This method converts a temperature in " + "degrees Fahrenheit to a temperature in degrees Celsius.")]
Code:
public double ConvertTemperature(double dFahrenheit)
{ testComNet.myClass obj=new testComNet.myClass();
double dC=obj.ConverFtoC(ref dFahrenheit);
obj=null;
return dC
}
}