.NET Framework Bookmark and Share   
 index > ASMX Web Services and XML Serialization > wsdl.exe to generate new proxy Reference.cs classes to obtain Begin... Async methods.
 

wsdl.exe to generate new proxy Reference.cs classes to obtain Begin... Async methods.

Hi,

Recently after upgrading an old Asp.Net application to Visual Studio 2008 .NET 3.0
some of my code was broken.

This happened because the WebReferences where updated and in doing so the Reference.cs files for each web services LOST the Begin / End Async methods for each WebMethod.

To fix this I had to manually run the wsdl.exe http://asdfasdfasdf/asdf.asmx,
and then copy the code of the generated proxy classes into the new Reference.cs classes generated by visual studio.
The new generated classes (manually created via wsdl.exe) created the Begin... methods.

Why has this been depracated?

Is there another way (new way) in VS2008 that one should do asynchronous calls like this to a webmethod in a webservice without waiting for a callback?
I.W Coetzer
I.W Coetzer
<!-- @page { margin: 2cm } P { margin-bottom: 0.21cm } -->



Nevermind, I did some research and found out that there are two ways to do this nowadays.
without having to change and project settings to create the reference.cs with thee old Begin / End Async methods.

1. OneWay calling of a WebMethod.
2. Asynchronously calling a WebMethod (page does not render though, until the WebMethod returns)


1. OneWay calling of a WebMethod.

Introduction

Sometimes you may want to call a webservice method, but not want to wait for a reply.
This can be accomplished by making use of the OneWay SoapDocumentMethod attribute.

    [SoapDocumentMethod(OneWay = true)]
    [WebMethod]
    public void LengthyFunctionOneWay(int milliseconds)
    {
        System.Threading.Thread.Sleep(milliseconds);
    }

        private wsLengthy.Service1 proxy = new wsLengthy.Service1();

        protected void btnCallLengthyWebServiceOneWay_Click(object sender, EventArgs e)
        {
        proxy.LengthyFunctionOneWay(20000);
        }



2. Asynchronously calling a WebMethod

Introduction

This article will discuss how to create and asynchronously call a webservice webmethod from an Asp.NET application. Please note that this method will asynchronously call the webmethod, however the web page that called the webmethod will not render until the webmethod has successfully returned.

Note: Asynchronously calling a webmethod does not mean that a web page will return immediately.

[WebMethod]
public void LengthyFunctionOneWay(int milliseconds)
{ 
        System.Threading.Thread.Sleep(milliseconds);

        return "Lengthy Function Returned after (" + 
                        milliseconds.ToString() + 
                        ") milliseconds.";
}

<%@ Page Language="C#" AutoEventWireup="true" Async="true" ...

using WebApplication1.wsLengthy;

private wsLengthy.Service1 proxy = new wsLengthy.Service1();

protected void btnCallLengthyWebService_Click(object sender, EventArgs e)
{
        proxy.LengthyFunctionCompleted += 
                                new LengthyFunctionCompletedEventHandler(OnLengthyCompleted);

        proxy.LengthyFunctionAsync(20000);
}

void OnLengthyCompleted(Object source, LengthyFunctionCompletedEventArgs e)
{ 
        Response.Write(e.Result.ToString());
}


I.W Coetzer
I.W Coetzer
I basically just want to call a webmethod on a webservice somewhere (.asmx) without waiting for a return.
let me know if there is a 'new' way to do this so that I don't have to manually generate the Reference.cs files using wsdl from the command line.

Thanks

I.W Coetzer
I.W Coetzer
<!-- @page { margin: 2cm } P { margin-bottom: 0.21cm } -->



Nevermind, I did some research and found out that there are two ways to do this nowadays.
without having to change and project settings to create the reference.cs with thee old Begin / End Async methods.

1. OneWay calling of a WebMethod.
2. Asynchronously calling a WebMethod (page does not render though, until the WebMethod returns)


1. OneWay calling of a WebMethod.

Introduction

Sometimes you may want to call a webservice method, but not want to wait for a reply.
This can be accomplished by making use of the OneWay SoapDocumentMethod attribute.

    [SoapDocumentMethod(OneWay = true)]
    [WebMethod]
    public void LengthyFunctionOneWay(int milliseconds)
    {
        System.Threading.Thread.Sleep(milliseconds);
    }

        private wsLengthy.Service1 proxy = new wsLengthy.Service1();

        protected void btnCallLengthyWebServiceOneWay_Click(object sender, EventArgs e)
        {
        proxy.LengthyFunctionOneWay(20000);
        }



2. Asynchronously calling a WebMethod

Introduction

This article will discuss how to create and asynchronously call a webservice webmethod from an Asp.NET application. Please note that this method will asynchronously call the webmethod, however the web page that called the webmethod will not render until the webmethod has successfully returned.

Note: Asynchronously calling a webmethod does not mean that a web page will return immediately.

[WebMethod]
public void LengthyFunctionOneWay(int milliseconds)
{ 
        System.Threading.Thread.Sleep(milliseconds);

        return "Lengthy Function Returned after (" + 
                        milliseconds.ToString() + 
                        ") milliseconds.";
}

<%@ Page Language="C#" AutoEventWireup="true" Async="true" ...

using WebApplication1.wsLengthy;

private wsLengthy.Service1 proxy = new wsLengthy.Service1();

protected void btnCallLengthyWebService_Click(object sender, EventArgs e)
{
        proxy.LengthyFunctionCompleted += 
                                new LengthyFunctionCompletedEventHandler(OnLengthyCompleted);

        proxy.LengthyFunctionAsync(20000);
}

void OnLengthyCompleted(Object source, LengthyFunctionCompletedEventArgs e)
{ 
        Response.Write(e.Result.ToString());
}


I.W Coetzer
I.W Coetzer

Here's some more information on the Event-based Asynchronous Pattern supported by WSDL.exe: http://msdn.microsoft.com/en-us/library/wewwczdw.aspx


Brain.Save() -- http://hyperthink.net/blog
Steve Maine

You can use google to search for other answers

Custom Search

More Threads

• Xml Serialisation of interface and abstract class
• Grid View
• WSDL "magic"
• Response Error From Web Service
• Determining what is in Webpart catalogs, on the page and clearing Catalogs
• Error with WebService method call
• ASP.NET Create XML On User Input
• To Check the validator controls without submit button
• Making a XmlElement Order property on .NET 1.1
• about custom classes (web service)