1

I am trying to asynchronously execute a web service from my ASP.NET web application. This particular web service (.asmx) belongs to the same project as my web application. I have noticed that when I reference the web service from another web application, I can call the web service asynchronously using the following code:

TestService service = new TestService();
service.TestMethod();

However, if I reference the web service via a separate web application, I notice that I have the option to execute it asynchronously using the following code:

ServiceProxy.TestService service = new ServiceProxy.TestService();        
service.TestMethodAsync();

The trick is, I want to asynchronously execute the web service from a web page that is in the same application as my web service. Is this possible? If so, how?

Is it possible to do this without putting my web service in a separate project?

Thank you,

4
  • The first code sample is an example of calling the method synchronously from within the same project, right? Not asynchronously as the question states. Commented Jul 1, 2009 at 18:54
  • No, it's worse. See my answer. Commented Jul 1, 2009 at 18:54
  • I caught that the OP was using the WebService implementation class directly and not calling it as a web service, but my point was that the question as written calls that an asynchronous call, when it is clearly synchronous. Commented Jul 1, 2009 at 18:58
  • It will be interesting to see when he replies. "Web Service in Same Project" usually equals confusion, and not intent. Commented Jul 1, 2009 at 19:13

3 Answers 3

2

First of all, I recommend you put your web services into a separate project.

Second, when you called:

TestService service = new TestService();
service.TestMethod();

you were falling into a trap that you made possible because they were in the same project. You were calling the TestMethod directly. That's not a web service call, it's a direct call to the TestMethod.

I suggest you put the service into another project, then use a Web Reference or Service Reference to access it from your web application.

EDIT: you could keep it in the same application, but that will continue to be confusing. You must always use a web reference or service reference if you're calling it as a web service.

If it's part of the same application, then why is it a web service at all?

Sign up to request clarification or add additional context in comments.

Comments

0

It could still reference the same application as a web service, couldn't it?

Comments

0

To avoid the confusion, you should probably not be calling your web service method directly at all. Leave that method to be called by ASP.Net in response to a web method request.

You can, however, move the implementation of your web method into another class that can be instantiated and called by both the web service class and your web application at any other time. With that class in place, if you want to call one of its methods asynchronously, you should look at creating a delegate and using BeginInvoke() and EndInvoke().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.