C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » WCF/Webservices »

Consuming web service using SOAP Protocol in ASP.Net


Posted Date: 19 Mar 2009    Resource Type: Articles    Category: WCF/Webservices
Author: banupriyaMember Level: Bronze    
Rating: 1 out of 5Points: 7



Introduction:


This article demonstrates how to create a web service using visual studio 2005 and also demonstrates how to consuming a web service using SOAP protocol.

please follow the steps to create a web service in visual studio 2005

step 1: creating a web service



->Start Microsoft Visual Studio .NET or Visual Studio 2005.
->Create a new ASP .NET Web service project. Name the Web service "DictionaryService".
->Change the name of the Solution file to "DictionaryService" for consistency.
->Change the name of the default Web service that is created from Service1.asmx to
"DictionaryService.asmx"
.

Define methods that encapsulate the functionality of your service. Each method must be flagged with a WebMethod attribute in front of it. Without this attribute, the method will not be exposed from the service.

->Add the following method to the "DictionaryService" class that you just created:

#region DictionaryService
[WebMethod(Description = "Returns the the tamil meaning for a given english word")]
public string EnglishToTamil(string strENG_Word)
{
DataTable dt = new DataTable();
dt = ReturnTAM(strENG_Word);
string strTam = dt.Rows[0][0].ToString();
return strTam;
}
public DataTable ReturnTAM(string strENG_Word)
{
string strTamil = "";
string strSQL = "select tam from dictionary where eng='" + strENG_Word + "'";
string connectionString = "Data Source=server;Initial Catalog=database;Integrated Security=True";
SqlConnection sqlCon = new SqlConnection(connectionString);
sqlCon.Open();

SqlCommand sqlCmd = new SqlCommand(strSQL, sqlCon);

SqlDataReader sqlDR = sqlCmd.ExecuteReader();

DataTable dt = new DataTable();
dt.Load(sqlDR);
sqlCon.Close();
return dt;
}
#endregion

->Click Build on the Build menu to build the Web service.
->Browse to the "DictionaryService.asmx" Web service page to test the Web service. If you set the local computer to host the page, the URL is
http://localhost/DictionaryService/DictionaryService.asmx.

Step 2: Consume Web Service Using SOAP Protocol



For consuming a web service using SOAP protocol, you need to create a Web application.

->create a new ASP.Net web application.
->click on “add reference“ and then select “Interop.MSXML2.dll” and click on add.
->Create one label to display result (ID = lblResult).
->Add the following source code in the code behind

using MSXML2;
protected void Page_Load(object sender, EventArgs e)
{
string strSoapEnvelope= "";
//SOAP Envelope
strSoapEnvelope = "";
strSoapEnvelope += " strSoapEnvelope += "xmlns:xsi = \"http://www.w3.org/2001/XMLSchema-instance\" ";
strSoapEnvelope += "xmlns:xsd= \"http://www.w3.org/2001/XMLSchema\" ";
strSoapEnvelope += "xmlns:soap= \"http://schemas.xmlsoap.org/soap/envelope/\">";
strSoapEnvelope += "";
strSoapEnvelope += "";
strSoapEnvelope += "Advertisement";
strSoapEnvelope += "
";
strSoapEnvelope += "
";
strSoapEnvelope += "
";


MSXML2.XMLHTTP xmlHTTP = new XMLHTTP();
xmlHTTP.open("Post", "http://localhost:2495/DictionaryService/DictionaryService.asmx", false, "", "");
xmlHTTP.setRequestHeader("SOAPAction", "http://tempuri.org/EnglishToTamil");
xmlHTTP.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHTTP.send(strSoapEnvelope.ToString());

lblResult.Text = xmlHTTP.responseText.ToString();

}

here is the Result
?????????

Conclusion:



There are many difference implementations for SOAP Service but the standard is there and we can start to build some useful applications on it. Although ASP.NET or SOAP web services have n number of features, if you want to consume the exposed Web Services in you clients, please make sure you have the latest libraries installed because standards continue evolving and all vendors try their best achieve the edge in such open standards war.



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Web service in ASP.Net  .  Web service  .  Creating a web service  .  Consuming web service using SOAP  .  Consuming web service  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: (WPF) Windows Presentation Foundation Interview Questions
Previous Resource: Consuming a WSDL Webservice from ASP
Return to Discussion Resource Index
Post New Resource
Category: WCF/Webservices


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use