Saturday, June 18, 2005

Programming Web Services with SOAP

TopXML : Programming Web Services with SOAP: "Invoking the Service Using SOAP

Creating a SOAP client for the Hello World service using .NET is, surprisingly, harder than creating the service itself. There are tools to make it easier (we will explore them briefly in Chapter 5), but for now we'll go through the steps manually so you know what is going on.

Again using your favorite text editor, create HelloWorld.cs (the .cs extension indicates C# source code) from Example 3-18.

Example 3-18: HelloWorld.cs, a C# HelloWorld Client

// HelloWorld.cs

using System.Diagnostics;
using System.Xml.Serialization;
using System;
using System.Web.Services.Protocols;
using System.Web.Services;

public class Example1 :
System.Web.Services.Protocols.SoapHttpClientProtocol {

public Example1( ) {
this.Url = 'http://localhost/helloworld.asmx ';

public string sayHello(string name) {
object[] results = this.Invoke('sayHello',
new object[] {name});
return ((string)(results[0]));

public static void Main(string[] args) {
Console.WriteLine('Calling the SOAP Server to say hello');
Example1 example1 = new Example1( );
Console.WriteLine('The SOAP Server says: ' +

The [System.Web.Services.WebserviceBindingAttribute] line tells the .NET managed runtime that this particular .NET assembly is going to be used to invok"
Post a Comment