WebService code: using system;
Using system. Web;
Using system. Web. Services;
Using system. Web. Services. Protocols;
[WebService (namespace = "http://tempuri.org/")]
[Webservicebinding (conformsto = wsiprofiles. basicprofile1_1)]
Public class service: system. Web. Services. WebService
{
Public Service (){
// If you use the designed component, uncomment the following line
// Initializecomponent ();
}
[Webmethod]
Public String helloworld (string strname ){
String strname1 = strname ?? "Radish ";
Return strname1 + "hello ";
}
}
1.1 asynchronous call: Because vs2003 is not available, it is written in # develop. Using system;
Using myservice = servicetest. Service;
Namespace servicetest
{
Class mainclass
{
Static iasyncresult iresult;
Static myservice. Service = new myservice. Service ();
Public static void main (string [] ARGs)
{
// Synchronous call
Console. writeline (service. helloworld (null ));
// Asynchronous call
Asynccallback callback = new asynccallback (callback );
Iresult = service. beginhelloworld ("radish Greens", callback, null );
Console. Read ();
}
Static void callback (iasyncresult IAR)
{
If (object. Equals (null, IAR ))
{
Console. writeline ("null ");
Return;
}
If (IAR. iscompleted)
{
Console. writeline (service. endhelloworld (IAR ));
}
}
}
}
2.0 asynchronous call: using system;
Using system. Collections. Generic;
Using system. text;
Using myservice = servicetest. firstservice;
Namespace servicetest
{
Class Program
{
Static void main (string [] ARGs)
{
Console. foregroundcolor = consolecolor. Green;
// Synchronous call
Myservice. Service = new myservice. Service ();
Console. writeline (service. helloworld (null ));
// Asynchronous call
Service. helloworldcompleted + = delegate (Object sender, myservice. helloworldcompletedeventargs E)
{
If (object. Equals (null, E. Error ))
{
Console. writeline (E. Result );
}
Else
{
Console. writeline (E. Error. Message );
}
};
Service. helloworldasync ("radish vegetables ");
Console. Read ();
}
}
}