Simple Example of asynchronous web service calling between 1.1 and 2.0

Source: Internet
Author: User
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 ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.