Showing posts with label web service. Show all posts
Showing posts with label web service. Show all posts

Tuesday, December 18, 2012

Consume ASMX web Service in ASP.NET 4.0

In last tutorial, we learn How to Create ASMX web Service in ASP.NET 4.0. This tutorial guides how to consume it.
  • Add new aspx page. Right click on Website and click 'Add New Item'. A new window will appear.
asp.net asmx web service

  • Select 'Web Form' and name it according to your choice.
asp.net asmx web service

  • Create new object of web service by writing following code:
MyFirstWebService svc = new MyFirstWebService();
  • Call web service method by writing following code:
svc.CallmyName("Waqas Ali");

asp.net asmx web service

Saturday, November 24, 2012

How to Create ASMX web Service in ASP.NET 4.0

Asmx Web Services are easy and simple to Create and use. This tutorial guides you how to write a ASMX Web Service step by step. 
  • Open Visual studio and create new Website. 
  • Right Click on Website and Click on 'Add New Item'.
asp.net asmx web service
  • A New Window will Open, select 'Web Service' , name it and click 'Add'.
asp.net asmx webservice
  • When you click 'Add' Button, new files ( with .asmx and .cs extensions ) will be added to Project.
  • Visual Studio will add some code in it.
  • A default Web Method named 'Helloworld' will also be added in it.
asp.net asmx Web Service
  • You have created ASMX Web Service Successfully.
  • Replace 'Helloworld' Web Method with following code.
  • This is Custom Web Method we created for our ASMX Web Service.

In next tutorial, we will learn how to use this Web Service.

Monday, July 2, 2012

Implement a Web Service in .NET

Explain with code sample how to Implement a Web Service in .NET?

Following is code in VBScript and C# both respectively.

In VBScript :


<%@ WebService Language="VBScript" Class="KmToMConvert" %>

Imports System
Imports System.Web.Services

Public Class KmToMConvert :Inherits WebService
   <WebMethod()> Public Function KilometerToMeter(ByVal Kilometer As String) As String 
         return (Kilometer * 1000)
         end function
end class

In C# :

[WebService(Namespace = http://tempuri.org/)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
     [WebMethod]
     public string HelloWorld()
     {
            return "Hello World";
     }
}