473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Something strange happened when asynchronously calling a web servi

I've just studied the "how to" web service and the async pattern in donnet.I
make a test with these knowledges,but I got a strange result. Here is my
test.
1.Write a simple "Add" service named MathWS( the class name),and put it in a
..asmx file named math.asmx in the "D:/winnt/interpub/wwwroot/mathws"
directory. "mathws" is my new-built directory.
2.run the http://localhost/mathws/math.asmx,find it works well,and run run
the http://localhost/mathws/math.asmx?wsdl,view source,copy the wsdl source
code to a file name math.wsdl,and I also put it in the mathws directory.
3.open command line window,key in command "disco
http://localhost/mathws/math.wsdl",ok,now a file named mathws.wsdl is
created under my now directory(the directory where I run disco command).
4.Still in the directory I type in "wsdl mathws.wsdl", a mathws.cs file is
created and it also has a MathWS class.This is my proxy class file which
include a synchronous "Add" method and two asynchronous asynchronous
BeginAdd and EndAdd method.the latter is used for callback.They accept two
int numbers and return their sum.
5.Now I am ready to write my client class two call the web service.Since the
EndAdd method return a int value instead of a "void one",so I write a class
"MathWSChild" which derives from the MathWS class,and add a new method just
like this:
public class MathWSChild:MathWS{
public void OutputResult(System.IAsyncResult asyncResult){
Console.WriteLine(this.EndAdd(asyncResult));
//*****Console.WriteLine("hello.");*******//
}
}
Now,I can use this method as the callback method.and the whole calling codes
maybe like this:
using System;

public class MathClient{

public static void Main(){
MathWSChild mathWSChild = new MathWSChild();
AsyncCallback cb = new AsyncCallback

(mathWSChild.OutputResult);
IAsyncResult asyncResult = mathWSChild.BeginAdd

(120,130,cb,new Object());
Console.ReadLine();
}

}
public class MathWSChild:MathWS{
public void OutputResult(System.IAsyncResult asyncResult){
Console.WriteLine(this.EndAdd(asyncResult));
/*****Console.WriteLine("hello.");*******/
}
}

I save these codes in a file mathclient.cs ,and now i have two files in
client directory,mathws.cs which includes my proxy class and the
mathclient.cs which includes the calling codes.

Maybe it will work well? After some necessary compiling ,just like this:
csc /t:library mathws.cs
csc /r:mathws.dll mathclient.cs

Now,I typed "mathclient.exe" in command line,
the "_" flashed,I know the code"Console.ReadLine();" worked , but nothing
else is outputed.when i cllick "Enter",the program ends.
I 've thought there is some buffer problems which I met when I studied the
async pattern,so I add " Console.Out.Flush()" after the
Console.WriteLine(this.EndAdd(asyncResult)); in the OutputResult method,but
no help.
finally, I add a line of code just like I wrote in the comment part in my
codes:
/*****Console.WriteLine("hello.");*******/
A miracle happened, two lines are outputed:

250
hello.
_

Of course the "Console.WriteLine("hello.");" maybe just a
"Console.WriteLine("");"
but I wonder why this could happened,and how to resolve this problem?After
all,I want to see the "250" without saying "hello" to the computer.

Thanks greatly for your help.

Nov 23 '05 #1
0 1348

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Sony Antony | last post by:
I have the following simple program in Solaris Forte compiler 5.4 producing the warning. Though it produces the warning, it works fine as expected. This has been compiling fine without any...
22
by: MLH | last post by:
I have some audio help files that play fine from within Access 97 and Access 2.0. Both are running on a Windows XP box. But I do not know what program plays the files. If I click Start, Run and...
11
by: Yoni Rabinovitch | last post by:
Is it possible to invoke a C# delegate/event handler asynchronously, from unmanaged C++ ? I assume this requires a Managed C++ wrapper, which would call BeginInvoke on the delegate ? Is this...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
6
by: Lak | last post by:
Hi all I am trying to call a C# method (in a DLL) asynchronously from VB. I don't know how to do this. Any suggestion is appreciated. Thanks.
5
by: Benzi Eilon | last post by:
I have written a C# application which should run as a Windows Service. I must avoid having multiple instances of the application on one machine so I inserted the following code at the beginning of...
14
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
160
by: DiAvOl | last post by:
Hello everyone, Please take a look at the following code: #include <stdio.h> typedef struct person { char name; int age; } Person;
20
by: Pilcrow | last post by:
This behavior seems very strange to me, but I imagine that someone will be able to 'explain' it in terms of the famous C standard. -------------------- code -----------------------------------...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.