Farhad
Farhad

Reputation: 205

How to invoke Web service after inserting a raw in a table

I have a program in which it insert a raw in a table after certain operations. I wan to call a web service in code behind to do some special tasks by the using of info that there is in the inserted row.

How I can do that?

Is it good idea to invoke this web service from a stored procedure or not? What are the other options?

More Details: Actually, I have an operation in my web application that take a long time to be completed and it is seriously time consuming operation. I don't want client wait until this process finish. That is why I decide write a web service to do this process in the background. Therefore, I think it may be a good idea that when client request receive I insert his request in a table and call a web service to handle it. Moreover, I do not want to wait until web service return the result, so I will aware client from its result through the report. I do not know what is the best solution to handle it.

Upvotes: 0

Views: 325

Answers (3)

tster
tster

Reputation: 18257

The problem it sounds like is that you cannot guarantee that the web service will be called unless you call it before committing the transaction. However, it sounds like the web service needs to be called after commit. In this case, it sounds like you should use a message queue. You could either build one in your database or you could use one off the shelf (http://aws.amazon.com/sqs/ or http://www.windowsazure.com/en-us/home/features/messaging/).

The steps would be:

  1. Insert message into queue (after this is success you can return the call, depending on what your contract with the caller is)
  2. Read message
  3. Insert into table
  4. Call web service
  5. Delete message

The downside is that you will need to make the operations (inserting into the table and calling the web service) idempotent.

Upvotes: 0

Pradeep Pati
Pradeep Pati

Reputation: 5919

It is never a good idea to call webservice from Stored procs or other DB objects. You can call it from your code, just after you execute the insert and commit it.

Upvotes: 1

Kristof
Kristof

Reputation: 3315

I usually keep myself far away from table triggers(it sounds like you're about to use an on insert trigger for a table).
I don't know your specific situation but you could either :

  • Call the webservice before or after you call the stored procedure, this way the data layer(stored proc) only handles data and nothing more. You're logical layer will handle the logic of calling an extra webservice.
  • Write a service that will periodicly read a table and notify the webservice of the latest modifications. More messy but it resembles more the effect you're trying to achieve.

There are probably more solutions but i'd need more information on what it exactly is you're doing.
Right now it's kinda vague :)

Upvotes: 1

Related Questions