Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / December 2005

Tip: Looking for answers? Try searching our database.

Asychronous web service call using WSE 3.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ershad - 07 Dec 2005 17:56 GMT
Hello,

I need to make multiple simultaneous asynchronous calls to a web service
using WSE 3.0. To make the asynchronously call I use the event based approach
by registering a handler for FooCompleted events and calling FooAsync like
this:

proxy.FooCompleted += new FooCompletedEventHandler (OnFooCompleted);
proxy.FooAsync (...);
...
void OnFooCompleted (Object source, FooCompletedEventArgs e)
{
   // Called when Foo completes
}

This work fine for a single call. But when I call FooAsync() multiple times
simultaneous, like this:

// Distinguish among asynchronous operation by
// providing a unique Guid.NewGuid() vallue for each call
for(int i=0; i<=10; i++)
  proxy.FooAsync (Guid.NewGuid());

I get the following exception

[System.InvalidOperationException] = {"WSE102: The asynchronous operation
has already completed. Invoke just once the End portion of an asynchronous
operation, with an instance of IAsyncResult."}

It is worth motioning that everything works fine when we use HTTP to call
the web service. That is when we call the web service without using WSE.

To generate the proxy we used th WSE tool
Hello,

I need to make multiple simultaneous asynchronous calls to a web service
using WSE 3.0. To make the asynchronously call I use the event based approach
by registering a handler for FooCompleted events and calling FooAsync like
this:

proxy.FooCompleted += new FooCompletedEventHandler (OnFooCompleted);
proxy.FooAsync (...);
...
void OnFooCompleted (Object source, FooCompletedEventArgs e)
{
   // Called when Foo completes
}

This work fine for a single call. But when I call FooAsync() multiple times
simultaneous, like this:

// Distinguish among asynchronous operation by providing a unique
//Guid.NewGuid() vallue for each call
for(int i=0; i<=10; i++)
  proxy.FooAsync (Guid.NewGuid());

I get the following exception

[System.InvalidOperationException] = {"WSE102: The asynchronous operation
has already completed. Invoke just once the End portion of an asynchronous
operation, with an instance of IAsyncResult."}

It is worth motioning that everything works fine when we use HTTP to call
the web service. That is when we call the web service without using WSE.

We used the WSE tool to generate the proxy client:
>Wsewsdl3.exe soap.tcp://localhost:2100/MyWebService /type:webClient

Thanks on before hand
/Ershad
GCR - 08 Dec 2005 14:40 GMT
Looks like the event handler is called more than once, at least that's what I
understand from the error message. I have a similar service which works just
fine.

> Hello,
>
[quoted text clipped - 66 lines]
> Thanks on before hand
> /Ershad
ershad - 08 Dec 2005 15:20 GMT
Hello,

Thanks a lot for your answer but unfortunately it didn't help much.
As I mentioned before my code works fine when I don't use WSE. Can you please
send me some sample code from how you have done it.

This is my code which fails.

class Program
{

    static void Main(string[] args)
    {
       Service myTcpClient = new Service();
       myTcpClient.HelloWorldCompleted += new
HelloWorldCompletedEventHandler(myTcpClient_HelloWorldCompleted);
       Console.WriteLine("Call Web Service by Asynchronous TCP ...");
       myTcpClient.HelloWorldAsync(Guid.NewGuid());    // One call Works fine!
       Console.WriteLine("Press ENTER Key to continue...");
       Console.ReadLine();

       // multiple simulantous calls
       for (int i = 0; i<20; i++)
       {
        myTcpClient.HelloWorldAsync(Guid.NewGuid()); // fails sporadically!
       }
       Console.WriteLine("Calls Completed...");
       Console.ReadLine();

    }

    static void myTcpClient_HelloWorldCompleted(object sender,
HelloWorldCompletedEventArgs e)
    {
       // The exception occurs here
       Console.WriteLine(e.Result);
    }
}

If anyone needs to look at the proxy client (generated with the WSE tool),
it is attached in this message.

I appreciate any help I can get!

Regards
/Ershad

> Looks like the event handler is called more than once, at least that's what I
> understand from the error message. I have a similar service which works just
[quoted text clipped - 70 lines]
> > Thanks on before hand
> > /Ershad
GCR - 08 Dec 2005 15:29 GMT
Here's a quick sample, which works fine:

namespace Consumer
{
   class Program
   {
       static void Main(string[] args)
       {
           Adapter ad = new Adapter();
           Console.ReadLine();
       }
   }
   class Adapter
   {
       MySvc.MyServiceWse proxy = null;
       

       public Adapter()
       {
           this.proxy = new Consumer.MySvc.MyServiceWse();
           this.proxy.MyWSOpCompleted +=new
Consumer.MySvc.MyWSOpCompletedEventHandler(proxy_MyWSOpCompleted);
           for (int i = 0; i <= 5; i++)
           {
               this.proxy.MyWSOpAsync(i.ToString(),(object)(Guid.NewGuid()));
               Console.WriteLine("Instance " + i.ToString() + " called!");
           }
           Console.WriteLine("Finished all calls!");
       }

       private void proxy_MyWSOpCompleted(Object sender,
MyWSOpCompletedEventArgs e)
       {
           Console.WriteLine("An instance retrurned: " + e.Result);
       }
   }
}

The proxy class looks like this:

   [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services",
"2.0.50727.42")]
   [System.Diagnostics.DebuggerStepThroughAttribute()]
   [System.ComponentModel.DesignerCategoryAttribute("code")]
   [System.Web.Services.WebServiceBindingAttribute(Name="MyServiceSoap",
Namespace="http://tempuri.org/")]
   public partial class MyServiceWse :
Microsoft.Web.Services3.WebServicesClientProtocol {
       
       private System.Threading.SendOrPostCallback MyWSOpOperationCompleted;
       
       private bool useDefaultCredentialsSetExplicitly;
       
       /// <remarks/>
       public MyServiceWse() {
           this.Url =
global::Consumer.Properties.Settings.Default.Consumer_MySvc_MyService;
           if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
               this.UseDefaultCredentials = true;
               this.useDefaultCredentialsSetExplicitly = false;
           }
           else {
               this.useDefaultCredentialsSetExplicitly = true;
           }
       }
       
       public new string Url {
           get {
               return base.Url;
           }
           set {
               if ((((this.IsLocalFileSystemWebService(base.Url) == true)
                           && (this.useDefaultCredentialsSetExplicitly ==
false))
                           && (this.IsLocalFileSystemWebService(value) ==
false))) {
                   base.UseDefaultCredentials = false;
               }
               base.Url = value;
           }
       }
       
       public new bool UseDefaultCredentials {
           get {
               return base.UseDefaultCredentials;
           }
           set {
               base.UseDefaultCredentials = value;
               this.useDefaultCredentialsSetExplicitly = true;
           }
       }
       
       /// <remarks/>
       public event MyWSOpCompletedEventHandler MyWSOpCompleted;
       
       /// <remarks/>
       
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/MyWSOp",
RequestNamespace="http://tempuri.org/",
ResponseNamespace="http://tempuri.org/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
       public string MyWSOp(string info) {
           object[] results = this.Invoke("MyWSOp", new object[] {
                       info});
           return ((string)(results[0]));
       }
       
       /// <remarks/>
       public void MyWSOpAsync(string info) {
           this.MyWSOpAsync(info, null);
       }
       
       /// <remarks/>
       public void MyWSOpAsync(string info, object userState) {
           if ((this.MyWSOpOperationCompleted == null)) {
               this.MyWSOpOperationCompleted = new
System.Threading.SendOrPostCallback(this.OnMyWSOpOperationCompleted);
           }
           this.InvokeAsync("MyWSOp", new object[] {
                       info}, this.MyWSOpOperationCompleted, userState);
       }
       
       private void OnMyWSOpOperationCompleted(object arg) {
           if ((this.MyWSOpCompleted != null)) {
               System.Web.Services.Protocols.InvokeCompletedEventArgs
invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
               this.MyWSOpCompleted(this, new
MyWSOpCompletedEventArgs(invokeArgs.Results, invokeArgs.Error,
invokeArgs.Cancelled, invokeArgs.UserState));
           }
       }
       
       /// <remarks/>
       public new void CancelAsync(object userState) {
           base.CancelAsync(userState);
       }
       
       private bool IsLocalFileSystemWebService(string url) {
           if (((url == null)
                       || (url == string.Empty))) {
               return false;
           }
           System.Uri wsUri = new System.Uri(url);
           if (((wsUri.Port >= 1024)
                       && (string.Compare(wsUri.Host, "localHost",
System.StringComparison.OrdinalIgnoreCase) == 0))) {
               return true;
           }
           return false;
       }
   }
ershad - 08 Dec 2005 16:09 GMT
This seems strange to me. I have done exactly the same thing! whats the
difference here. Have you tried more than 5 simulantous calls?  I have
managed to make up to 10 calls without getting an exception. This is driving
me nuts!

> Here's a quick sample, which works fine:
>
[quoted text clipped - 148 lines]
>         }
>     }
ershad - 08 Dec 2005 16:52 GMT
I know why your code works! You are using HTTP. I am after Asynchrous calls
by TCP. As I mentioned a couple of times the calls work fine with HTTP (refer
to the URL in my proxy class). My web service is hosted inside a windows
service.

This must be bug in the WSE.

Regards
/Ershad  

> Here's a quick sample, which works fine:
>
[quoted text clipped - 148 lines]
>         }
>     }
ershad - 08 Dec 2005 17:01 GMT
I know why your code works! You are using HTTP. As I have mentioned a couple
of times the calls work fine with HTTP. I am after asynchronous calls using
TCP (please refer to the url in the proxy class). My web service is hosted
inside a windows service.  

It seems that there is a bug in WSE.

> Here's a quick sample, which works fine:
>
[quoted text clipped - 148 lines]
>         }
>     }
ershad - 08 Dec 2005 15:29 GMT
Forgot the proxy client in my last mail :-) Here it is

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.42
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

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

//
// This source code was auto-generated by wsdl, Version=2.0.50727.42.
//

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="ServiceSoap",
Namespace="http://tempuri.org/")]
public partial class Service :
Microsoft.Web.Services3.WebServicesClientProtocol {
   
   private System.Threading.SendOrPostCallback HelloWorldOperationCompleted;
   
   /// <remarks/>
   public Service() {
       this.Url = "soap.tcp://localhost:1190/Service";
   }
   
   /// <remarks/>
   public event HelloWorldCompletedEventHandler HelloWorldCompleted;
   
   /// <remarks/>
   
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/HelloWorld",
RequestNamespace="http://tempuri.org/",
ResponseNamespace="http://tempuri.org/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
   public string HelloWorld() {
       object[] results = this.Invoke("HelloWorld", new object[0]);
       return ((string)(results[0]));
   }
   
   /// <remarks/>
   public System.IAsyncResult BeginHelloWorld(System.AsyncCallback
callback, object asyncState) {
       return this.BeginInvoke("HelloWorld", new object[0], callback,
asyncState);
   }
   
   /// <remarks/>
   public string EndHelloWorld(System.IAsyncResult asyncResult) {
       object[] results = this.EndInvoke(asyncResult);
       return ((string)(results[0]));
   }
   
   /// <remarks/>
   public void HelloWorldAsync() {
       this.HelloWorldAsync(null);
   }
   
   /// <remarks/>
   public void HelloWorldAsync(object userState) {
       if ((this.HelloWorldOperationCompleted == null)) {
           this.HelloWorldOperationCompleted = new
System.Threading.SendOrPostCallback(this.OnHelloWorldOperationCompleted);
       }
       this.InvokeAsync("HelloWorld", new object[0],
this.HelloWorldOperationCompleted, userState);
   }
   
   private void OnHelloWorldOperationCompleted(object arg) {
       if ((this.HelloWorldCompleted != null)) {
           System.Web.Services.Protocols.InvokeCompletedEventArgs
invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
           this.HelloWorldCompleted(this, new
HelloWorldCompletedEventArgs(invokeArgs.Results, invokeArgs.Error,
invokeArgs.Cancelled, invokeArgs.UserState));
       }
   }
   
   /// <remarks/>
   public new void CancelAsync(object userState) {
       base.CancelAsync(userState);
   }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
public delegate void HelloWorldCompletedEventHandler(object sender,
HelloWorldCompletedEventArgs e);

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class HelloWorldCompletedEventArgs :
System.ComponentModel.AsyncCompletedEventArgs {
   
   private object[] results;
   
   internal HelloWorldCompletedEventArgs(object[] results, System.Exception
exception, bool cancelled, object userState) :
           base(exception, cancelled, userState) {
       this.results = results;
   }
   
   /// <remarks/>
   public string Result {
       get {
           this.RaiseExceptionIfNecessary();
           return ((string)(this.results[0]));
       }
   }
}

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.