Groups > Borland > Dellphi web services soap > Re: Asynchronous Call to a second web service from a web service




Asynchronous Call to a second web service from a web service

Asynchronous Call to a second web service from a web service
Thu, 10 Apr 2008 12:09:40 -050
After experimentation, I found I could call a second web service from
inside of another web service (using the synchronous invocation).

Great!

So, can I call the second web service asynchronously?

(Why?  A rather annoying client who will not learn how to call my web
service asynchronously, but doesn't want to be waiting for my web
service to process.)

For example:

(Assume TWebService2 defines a web method that takes a string as a
parameter and returns a string after some processing.)

procedure TWebService1.ACallBack(IAR: IAsyncResult);
var
  AWebService2: TWebService2;
  AString: string;
begin
  AWebService2 := TWebService2(IAR.AsyncState);  
  AString := AWebService2.EndSomeWebMethod(IAR);

  //Do some other processing with the returned string
  //including notifying client of results
end;

TWebService1 declares and defines this web method (synchronous):

function TWebService1.ReceiveXML(XMLString: string): string;
var
  AWebService2: TWebService2;
begin
  AWebService2 := TWebService2.Create;
  AWebService2.BeginSomeWebMethod(XMLString, Self.ACallBack,
AWebService2);

//Processing ends here, original caller not waiting
  Result := 'Processing...';
end;

What I am worried about is what happens when the "Result :=
'Processing...'; gets sent to the original caller and that function
exits?  Will the execution and thread of the WebService1 instannce end
and then the callback will never be used?

Aside from forcing the client to call the web service himself
asynchronously (which I cannot do) is there another, more elegant way
of achieving this?

Post Reply
Re: Asynchronous Call to a second web service from a web service
Sun, 13 Apr 2008 12:01:18 -070
Hello,

> What I am worried about is what happens when the "Result :=
> 'Processing...'; gets sent to the original caller and that function
> exits?  Will the execution and thread of the WebService1 instannce end
> and then the callback will never be used?

Yes, the thread handling WebService1 will end when the method returns.
However, that should not be an issue if you're invoking WebService2
asynchronously. I assume you'll be invoking WebService2 on a new thread
[else it would not be an async. call]... that new thread will be around to
handle callback. My issue is whether you need to get results from
WebService2 back to the client? Maybe not if it's just a 'One-Way' (kind-of)
request.


> Aside from forcing the client to call the web service himself
> asynchronously (which I cannot do) is there another, more elegant way
> of achieving this?

If the client's view of the world is a Request|Response pair, then it does
not matter how you handle the server-side... at the end of the day, the
client expects the results of its request in the response.

Is your goal to have the client not block on a request? Or are you more
worried about the service being blocked processing a lengthy request and you
want to offload the server's processing to another service.

There are definite patterns used out there for async WebService calls.
However, it's not possible to implement them in a way that leaves the client
untouched.
(See http://msdn2.microsoft.com/en-us/library/aa480512.aspx,
http://www.ibm.com/developerworks/library/ws-asynch2/index.html, etc).

Cheers,

Bruneau.

Post Reply
about | contact