|
|
|
|
|
 |
Articles |
| Database(11) |
|
|
|
| Desktop Development(3) |
|
|
|
| Development Lifecycle(2) |
|
|
|
| Dot Net Nuke(1) |
|
|
|
| Enterprise Systems(1) |
|
|
|
| Frameworks & Libraries(0) |
|
|
|
| General Programming(25) |
|
|
|
| General Reading(6) |
|
|
|
| Graphics / Design(10) |
|
|
|
| Languages(2) |
|
|
|
| Mentor Resources(0) |
|
|
|
| Mobile Development(3) |
|
|
|
| Multimedia(0) |
|
|
|
| Research Papers(1) |
|
|
|
| Social Media(1) |
|
|
|
| Software Engineering(3) |
|
|
|
| Third Party Products(0) |
|
|
|
| Web Development(11) |
|
|
|
|
|
|
 |
 |
 |
|
|
 |
Articles |
 |
|
|
How to write a simple Web Service in .Net
Write a simple .asmx Web service
- Start Visual Studio .NET or Visual Studio 2005.
- Create a new Active Server Pages (ASP) .NET Web service project. Name the Web service MathService and point the location to an appropriate Web server that is running ASP.NET if necessary.
- Change the name of the Solution file to MathService for consistency.
- Change the name of the default Web service that is created from Service1.asmx to MathService.asmx.
- Click Click here to switch to code view in the designer environment to switch to code view.
Change the name of the class from Public Class Service1 to Public Class MathService.
- Define methods that encapsulate the functionality of your service. Each method that will be exposed from the service must be flagged with a WebMethod attribute in front of it. Without this attribute, the method will not be exposed from the service.
NOTE: Not every method needs to have the WebMethod attribute. It is useful to hide some implementation details called by public Web service methods or for the case in which the WebService class is also used in local applications. A local application can use any public class, but only WebMethod methods will be remotely accessible as Web services.
Add the following method to the MathServices class that you just created:
Public Function Add(a As Integer, b As Integer) As Integer
Return(a + b)
End Function
Public Function Subtract(A As System.Single, B As System.Single) As System.Single
Return A - B
End Function
Public Function Multiply(A As System.Single, B As System.Single) As System.Single
Return A * B
End Function
Public Function Divide(A As System.Single, B As System.Single) As System.Single
If B = 0
Return -1
End If
Return Convert.ToSingle(A / B)
End Function
- Click Build on the Build menu to build the Web service.
- Browse to the MathService.asmx Web service page to test the Web service. If you set the local computer to host the page, the URL is http://localhost/MathService/MathService.asmx.
The ASP.NET runtime returns a Web Service Help Page that describes the Web service. This page also enables you to test different Web service methods.
Average: 5.0000,
Total Ratings: 1
|
|
 |
| There is no message currently |
 |
|
 |
|
|
|