1

I have an ASP.NET Webform which currently calls a Java WebService. The ASP.NET Webform is created/maintained inhouse, whereas the Java WS is a package solution where we only have a WS interface to the application.

The problem is, that the Java WS is sometimes slow to respond due to system load etc. and there is nothing I can do about this. So currently at the moment there is a long delay on the ASP.NET Webform sometimes if the Java-WS is slow to respond, sometimes causing ASP.NET to reach its timeout value and throw the connection.

I need to ensure data connectivity between these two applications, which I can do by increasing the timeout value, but I cannot have the ASP.NET form wait longer than a couple of seconds.

This is where the idea of a queuing system comes into place.

My idea is, to have the ASP.NET form build the soap request and then queue it in a local queue, where then a Daemon runs and fires off the requests at the Java-WS.

Before I start building something from scratch I need a couple of pointers.

  1. Is my solution viable ?
  2. Are there any libraries etc already out there that I can achieve this functionality with ?
  3. Is there a better way of achieving what i am looking for ?
general exception
  • 4,202
  • 9
  • 54
  • 82
  • 1
    Are you still using ASMX web services? That's a legacy technology and you should be using WCF instead. – John Saunders Mar 23 '12 at 16:00
  • 2
    He's not using ASMX. Its a Web Form calling a Java Web Service. That being said, have you considered calling the Java Web Service asynchronously. – William Xifaras Mar 23 '12 at 16:05
  • 1
    @William yes have considered this but once the request is fired off to the Web Service async, the Web Form is closed and the user is returned to the calling system, so there would not be an instance for a callback to return to if you get me. – general exception Mar 23 '12 at 16:15
  • 1
    @JohnSaunders what exactly is the difference between asmx services and WCF. I need to read up on WCF. – general exception Mar 23 '12 at 16:17
  • 2
    Yes, you need to read up on WCF. It replaced ASMX six years ago! See [WCF vs. ASMX Web Services](http://stackoverflow.com/questions/2448472/wcf-vs-asmx-web-service) and the [tag:wcf] tag. – John Saunders Mar 23 '12 at 16:35
  • 1
    Are you using "Add Web Reference", or "Add Service Reference"? – John Saunders Mar 23 '12 at 16:36
  • 1
    Then you're using the client side of the ASMX technology. Simply switching to "Add Service Reference" will go a long way. It won't solve your problem directly, but it will at least get you out of the past. – John Saunders Mar 23 '12 at 16:40
  • 2
    The most important difference is that you can host the WCF service in any kind of application, including a Windows Service, without the need of a web server. As the windows service never stops (unless there's an exception, be careful!) it can expose a web service (WCF service exposed as WS endpoint). This windows service can act as a proxy receivig calls from the ASP.NET app and handling them as asynchronous requests to the java web service, so that it doesn't lock and can attend more incoming calls. When the java web service gives the response, it can be dalt with in a callback function. – JotaBe Mar 23 '12 at 18:18

3 Answers3

3

You can create a WindowsService hosting a WCF service.

Your web app can them call the WCF methods of your Windows Service.

Your windows service can call the java web service methods asynchronously, using the begin/End pattern

Your windows service can even store the answers of the java web service, and expose them through another WCF methods. For example you could have this methods in your WCF service:

1) a method that allows to call inderectly a java web service and returnd an identifier for this call

2) another method that returns the java web service call result by presenting the identifier of the call

You can even use AJAX to call the WCF methods of your Windows Service.

JotaBe
  • 38,030
  • 8
  • 98
  • 117
  • 1
    Since he is looking for a queue, this solution can be taken a bit further by incorporating a queue table within the database. – William Xifaras Mar 23 '12 at 16:21
  • 1
    Maybe not neccessary, if he simply wants to ensure that the calls to the java web service are processed. The Windows service can do it safely, without needin to use queues. – JotaBe Mar 23 '12 at 18:20
2

you could use MSMQ for queuing up the requests from you client. Bear in mind that MSMQ doesn't handle anything for you - it's just a transport.

All it does is take MSMQ messages and deliver them to MSMQ queues.

The creation of the original messages and the processing of the delivered messages is all handled in your own code on the sending and receiving machines: the destination machine would have to have MSMQ installed plus a custom service running to pick them up and process them

Anyway there is a librays for interop with MSQM using JAVA : http://msmqjava.codeplex.com/

Another way could be you can create a queue on one of your windows box and then create a service that pick up the messages form the Queue and foreward them to the Java service

Massimiliano Peluso
  • 26,379
  • 6
  • 61
  • 70
  • 1
    the destination machine would have to have MSMQ installed plus a custom service running to pick them up and process them Anyway there is a librays for interop with MSQM using JAVA http://msmqjava.codeplex.com/ – Massimiliano Peluso Mar 23 '12 at 13:49
  • 1
    this is not an option. The only entry point to the destination I have is a WebService interface. I cannot install anything on the Destination server. – general exception Mar 23 '12 at 13:51
  • 1
    yep your last paragraph pretty much sums up whats ive been thinking of doing. – general exception Mar 23 '12 at 13:56
2

You have two separate problems:

  1. Your web form needs to learn to send a request to a service and later poll to get the results of that service. You can do this by writing a simple intermediate service (in WCF, please) which would have two operations: one to call the Java service asynchronously, and the other to find out whether the async call has completed, and return the results if it has.
  2. You may need to persistently queue up requests to the Java service. The easiest way to do this, if performance isn't a top concern (and it seems not to be), is to break the intermediate service in #1 into two: one half calls the other half using a WCF MSMQ binding. This will transparently use MSMQ as a transport, causing queued requests to stay in the queue until they are pulled out by the second half. The second half would be written as a Windows service so that it comes up on system boot and starts emptying the queue.
John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • 1
    In no 1. you say "later poll to get the results of that service" I dont really want the input form to care what the result was, but i need something to care, possibly a reporting daemon of some kind built into the windows service, or write to event log etc. – general exception Mar 23 '12 at 19:22
  • 1
    any pointers on some good books for learning WCF ?? Learning WCF, A Hands-on Guide by Michele Leroux ?? – general exception Mar 24 '12 at 09:28
  • 2
    I'm afraid that Michele's book is out of date, especially if you're using .NET 4.0 or above. See [Beginner's Guide to WCF](http://msdn.microsoft.com/en-us/netframework/dd939784), especially the "Tutorials and Articles" section. .NET 4.0 has made WCF even easier to start with by eliminating much of the scary configuration file stuff. If you've got Visual Studio 2010, try just creating a "WCF Service Application" and looking at the code it created. – John Saunders Mar 24 '12 at 14:58
  • 1
    In #2, you say break the service into two half's, so the first half would have an endpoint, and would drop the data into a MSMQ queue, the second half would read the queue and process the data right ??? – general exception Mar 26 '12 at 09:28
  • 1
    I am marking this as the answer as it has provided me more intricate detail as to the best solution, even though JotaBe's post is clearly explaining a similar thing. – general exception Mar 26 '12 at 15:29