Home | | C Sharp and .NET Framework(CNF) | XML Web Service Application

Chapter: C# and .NET Framework

XML Web Service Application

On your local computer (localhost), start Visual Studio .NET. On the File menu, click New and then click Project. Under Project types click Visual Basic Projects, then click ASP.NET Web Service under Templates. Name the project TestService.

XML WEB SERVICE APPLICATION

 

 

Ø   On your local computer (localhost), start Visual Studio .NET. On the File menu, click New and then click Project. Under Project types click Visual Basic Projects, then click ASP.NET Web Service under Templates. Name the project TestService.

 

Ø   In Solution Explorer, change the name of Service1.asmx to Services.asmx.

 

Ø   Open Services.asmx in the visual designer. In the Properties window, change the Name property of the Service1 class to Services.

 

Ø   Save the project.

 

Create the XML Web Service Methods

Ø   Open Services.asmx in the code editor.

 

Ø   Add the following code within the Services class definition to create various Web methods:

 

<WebMethod()> Public Function GetMessage() As String Return "Today is the day"

 

End Function <WebMethod()> _

 

Public Function SendMessage(ByVal message As String) As String Return "Message received as: " & message

 

End Function <WebMethod()> _

 

Public Function ReverseMessageFunction(ByVal message As String) As String Return StrReverse(message)

 

End Function

 

<WebMethod()> Public Sub ReverseMessageSub(ByRef message As String) message = StrReverse(message)

 

End Sub Save and build the project.

 

Test the Services with Visual Studio .NET

Ø   In Solution Explorer, right-click Services.asmx and then click View in Browser.

 

Ø   Follow these steps to use the built-in browser to test each Web method:NOTE: You cannot test the ReverseMessageSub procedure because it expects a ByRef argument.

 

·  Click the hyperlink for the method that you want to test.

·  Fill in any requested message parameter values.

·  Click Invoke.

·  View the resulting XML and close the results window.

 

·  Click the Back button to return to the method list and repeat the steps for the remaining Web methods.

 

·  Close the built-in browser.

 

Create the Test Client Application

Ø   On the File menu, click Add Project, and then click New Project.

 

Ø   Select Visual Basic Console Application, and then name the project TestHarness.

 

Ø   On the Project menu, click Add Web Reference.

 

Ø   In the Address field, type http://localhost/TestService/Services.asmx, and then click Go.

 

Ø   Click Add Reference to finish creating the Web reference.

 

Ø   In Solution Explorer, right-click localhost in the Web References folder, click Rename, and then change the name to WebService. This becomes the namespace that is used within the test application to refer to the Services class.

 

Create the Test Code

Open Module1.vb and locate the Sub Main procedure.

 

Paste the following code in the file to call the appropriate Web methods: Dim strValue As String = "This is my message"

 

Dim myService As New WebService.Services() Console.WriteLine(myService.GetMessage) Console.WriteLine(myService.SendMessage(strValue)) Console.WriteLine(myService.ReverseMessageFunction(strValue)) myService.ReverseMessageSub(strValue) Console.WriteLine(strValue)

 

 

 

 

Test the Client Application

Ø   Create a breakpoint on the following line:

 

Ø   Console.WriteLine(myService.GetMessage)

 

Ø   In Solution Explorer, right-click the TestHarness project, and then click Set as StartUp Project.

 

Ø   On the Debug menu, click Start and wait for the program to enter debug mode.

 

Ø   On the Debug menu, click Windows, and then click Locals. Use the Locals window to view the value of the strValue variable during the debugging to observe any changes that are made to the variable.

 

Ø   On the Debug toolbar, use Step Into to step through each line of code from the TestHarness client into the XML Web service.

 

Ø   Before you end the Main subroutine, confirm that the output in the console window is as expected.

Ø   When the program ends, remove the breakpoint and close Visual Studio .NET.

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
C# and .NET Framework : XML Web Service Application |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.