none
Status response? RRS feed

  • Question

  • Hi,

    I have a web service that call a specific database function. I need to call that inside a web site and a mobile device, but i need to know if mobiles and web site receives the answer from web service(e.g: network down on mobile device, then web service should execute another function)

    Is that possible?


    If you get your question answered, please come back and Alternate TextMark As Answer.
    Web Developer

    Friday, June 20, 2014 4:34 PM

All replies

  • If the service call fails you'll get an error back (what form that error takes depends upon how you're calling it).  In your error handling code you can do whatever you want (including calling another web service).

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Friday, June 20, 2014 4:48 PM
    Moderator
  • If the service call fails you'll get an error back (what form that error takes depends upon how you're calling it).  In your error handling code you can do whatever you want (including calling another web service).

    Michael Taylor
    http://msmvps.com/blogs/p3net

    I dont know if what i want is the service calls, actually, i wanna know if website/mobile receives the service response, in case dont, then execute another web service function. For example.

    Mobile -> Web service -> Database function A
    Database function A -> Web service -> mobile receives - OK
                                                              -> mobile network down
                                                                   -> web service -> database function b

    I dont know if its possible to handle that, in more simple words, i wanna execute a transaction on my database, if the user dont receive the response, my service needs to be able to rollback that transaction.


    If you get your question answered, please come back and Alternate TextMark As Answer.
    Web Developer

    Friday, June 20, 2014 4:56 PM
  • From the web service side you cannot tell if the client would made the call actually got the response. More correctly you cannot confirm that the client did anything with the response. You can detect if the client connection is lost but if the connection fails while you're sending the response (or perhaps while bouncing across the network) then you wouldn't know.

    It sounds like you really need to implement an acknowledgement process.  When the client sends the initial request you should apply (but not commit) the changes.  Then have the client send a separate "acknowledge" request to actually commit the changes.  When the acknowledge request is received you commit the changes.  If you don't receive that then you'd rollback.

    The bigger issue is that service calls are, in general, stateless so the instance that handles the first request might not be the same instance that handles the second request.  Therefore a normal transaction wouldn't work as you're in potentially 2 different instances of the service.  If you need this kind of behavior then you'll need to modify your service implementation to control the lifetime.  In the case of WCF you can apply attributes to your service class that help control the lifetime.  For more information you should read this MSDN article.  In your specific case you'd want to set the lifetime such that each client gets its own instance when it connects and it continues to use that instance until it is closed.  You could then implement a transaction.  But this will impact concurrency and scaleability so you should carefully read through the docs and determine if the costs are worth it for your needs.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Friday, June 20, 2014 5:12 PM
    Moderator
  • From the web service side you cannot tell if the client would made the call actually got the response. More correctly you cannot confirm that the client did anything with the response. You can detect if the client connection is lost but if the connection fails while you're sending the response (or perhaps while bouncing across the network) then you wouldn't know.

    It sounds like you really need to implement an acknowledgement process.  When the client sends the initial request you should apply (but not commit) the changes.  Then have the client send a separate "acknowledge" request to actually commit the changes.  When the acknowledge request is received you commit the changes.  If you don't receive that then you'd rollback.

    The bigger issue is that service calls are, in general, stateless so the instance that handles the first request might not be the same instance that handles the second request.  Therefore a normal transaction wouldn't work as you're in potentially 2 different instances of the service.  If you need this kind of behavior then you'll need to modify your service implementation to control the lifetime.  In the case of WCF you can apply attributes to your service class that help control the lifetime.  For more information you should read this MSDN article.  In your specific case you'd want to set the lifetime such that each client gets its own instance when it connects and it continues to use that instance until it is closed.  You could then implement a transaction.  But this will impact concurrency and scaleability so you should carefully read through the docs and determine if the costs are worth it for your needs.

    Michael Taylor
    http://msmvps.com/blogs/p3net


    Before ask this question, i was reading this link 3 Ways WCF - CodeProject , but i was unable to implement something that help me in. And WCF Transactions, even looking at MSND, still sounds confuse to me, if you have a better explain, link, something to me.

    If you get your question answered, please come back and Alternate TextMark As Answer.
    Web Developer

    Friday, June 20, 2014 5:27 PM
  • I have found the book "Programming WCF Services" by Juval Lowy to be a good reference.  Specifically he has an entire chapter dedicated to using transactions with WCF services.  I would recommend reading it.

    This thread seems to be gravitating toward WCF so I'm going to move it to that forum so some of the WCF experts can chime in.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Friday, June 20, 2014 5:48 PM
    Moderator