470,833 Members | 1,251 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

Confusion over Asynchronous Web Methods

I am building Web Services using Visual Basic 2005 in VB.Net 2.0 and based on
MSDN Help and various other books I am lead to believe that when I generate a
proxy I should have a BeginMethodName and EndMethodName for each web method
that I build.

What I find is that when I consume the Web Service with a Web Form Client
the methods are there but when I consume the same Web Service with a Windows
Client the Begin/End methods are not there. I do see a MethodNameAsync
method and wondering if that is the same as the BeginMethodName.

Does anyone have any explaination for this?

George

Jun 7 '06 #1
2 1347
Hi, I had the same problem a few days ago... I learned about
asyncronous call (on MSDN) from client to web service, but the methods
"begininvoke" end "endInvoke" are supported and automatically created
only in .NET 2003!
In Visual Studio 2005 it is quite different and very simple. This is my
code client-side (C#, non VB, but the same logic...):

try
{

mywebServiceInstance.WebMethodNameCompleted +=
new
localhost.WebMethodNameCompletedEventHandler(myweb ServiceInstance_WebMethodNameCompleted);
mywebServiceInstance.WebMethodNameAsync(parameters );

}
//the autogenerated method WebMethodNameAsync is the equivalent of
//Begin... and End..., and it returns void

catch (SoapException se)
{
MessageBox.Show(se.Message, "SoapException");
}

//this is my handler of async transaction completed
private void mywebServiceInstance_WebMethodNameCompleted(object
sender, localhost.WebMethodNameCompletedEventArgs e)
{
Variable result;
try
{
result = e.Result;
}
...

It works good!
Tell me if you understood...
Ciao!!!

Jun 8 '06 #2
OK, Thanks for clearing that up. I was very confused becuase the Begin/End
methods are available for the Web Clients and Async for the Windows Clients.
I dug a little more in MSDN help (where sometimes it shows the old way and
sometimes the new) and found the following MSDN Topic to the most helpful for
my situation:
How to: Access an XML Web Service Asynchronously in Managed Code link is
internally at
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_radcon/html/0311dbe2-e7dc-43e0-915a-ff3e35aee084.htm

My VB client side code turned out something like this:

At the top of my class...
Dim WithEvents myWebService As New SecurityService.SecurityService

'Event that fires when the service method is finished and contains the results
Private Sub ApplicationOptionComplete(ByVal sender As Object, _
ByVal completed As
SecurityService.ApplicationOption_GetRecordsComple tedEventArgs) _
Handles myWebService.ApplicationOption_GetRecordsCompleted
' Insert code to implement the method here

Try
'The passed back information is contained in the .Result property
Dim MyAppOptionCol As New
ApplicationOptionCollection(completed.Result)

Dim MyAppSetting As ApplicationSetting
MyAppSetting = mAppSettingCol.GetByOid(NodeIndex)

PopulateForm(MyAppSetting, MyAppOptionCol)
System.Windows.Forms.Cursor.Current = Cursors.Default

Catch ex As Exception
HandleError(ex)

End Try
End Sub

Code that fires the Asynch method:
'Asynch Call
myWebService.Credentials =
System.Net.CredentialCache.DefaultCredentials

myWebService.ApplicationOption_GetRecordsAsync(Get UserGuid, AppSettingOid)

I hope this might help someone else.
George
"Giulio" wrote:
Hi, I had the same problem a few days ago... I learned about
asyncronous call (on MSDN) from client to web service, but the methods
"begininvoke" end "endInvoke" are supported and automatically created
only in .NET 2003!
In Visual Studio 2005 it is quite different and very simple. This is my
code client-side (C#, non VB, but the same logic...):

try
{

mywebServiceInstance.WebMethodNameCompleted +=
new
localhost.WebMethodNameCompletedEventHandler(myweb ServiceInstance_WebMethodNameCompleted);
mywebServiceInstance.WebMethodNameAsync(parameters );

}
//the autogenerated method WebMethodNameAsync is the equivalent of
//Begin... and End..., and it returns void

catch (SoapException se)
{
MessageBox.Show(se.Message, "SoapException");
}

//this is my handler of async transaction completed
private void mywebServiceInstance_WebMethodNameCompleted(object
sender, localhost.WebMethodNameCompletedEventArgs e)
{
Variable result;
try
{
result = e.Result;
}
...

It works good!
Tell me if you understood...
Ciao!!!

Jun 8 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by hs | last post: by
8 posts views Thread by Z D | last post: by
1 post views Thread by Julian Hershel | last post: by
5 posts views Thread by rgarf | last post: by
4 posts views Thread by taskswap | last post: by
1 post views Thread by dba123 | last post: by
3 posts views Thread by archana | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.