How to create an Event on a Webservice

Asked

Viewed 121 times

4

I have a Webservice that has a method that records a new entry record and updates the list that contains those entries. Now I need the customer to sign up for a Webservice event so that whenever a new record is added the event is fired at the customer, so he can do the necessary checks.

  • what you’ve already done?

  • The part of receiving the customer’s data and recording in the database. It is a two-pronged system, a reception and another supervision. Both communicate with the webservice. I searched on google some solutions, but are using Signalr and the whole system does not use Signalr.

  • You are using Webapi?

  • @jbueno is in Soap

  • And he is WCF or ASMX?

  • @jbueno he is asmx :)

  • SOAP is not made for this. In SOAP you make a request and get an answer, and nothing else. You will really depend on something like Signalr or a message queue system.

Show 2 more comments

1 answer

4


Simply and without knowing much of your environment, you will need to create a kind of Schedule. A program console, who has a timer or that it is programmed to run from time to time, observing the records in the table that your WS will insert. Whenever he finds something new there, he fires the action you desire.

Below is a very generic example of how to perform a Schedule to process from time to time, according to the parameters you want.

    public void ProcessarRotinas()
    {
       try
        {

            while (true)
            {
                for (int i = 1; i <= TentativasErro; i++)
                {
                    try
                    {
                        //Aqui vai toda sua regra de negócio
                        ExecutarRegra();
                        Thread.Sleep(ValordePausa * 1000);
                        break;
                    }

                    catch (Exception ex)
                    {                                                
                        Thread.Sleep(ValordePausa * 1000);
                    }
                }


            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
  • 1

    @Júniormoreira This answer offers an alternative, since there is no two-way communication using SOAP. I particularly find a valid alternative and even used this type of solution (schedule in the client a regular consultation to the webservice since the webservice could not notify the client).

  • @Júniormoreira, at the moment I am working on a similar situation, and Schedule was a very viable and functional solution.

  • @Caffé, @Deividramon, I didn’t add the comment, came direct from From Review which I understood was a better option to add a comment instead of an answer! Rewords the answer to make it more complete, because the question itself is already complicated! will earn my +1 once I improve, I will bookmark and wait for the improvement!

  • @Juniors understood! I will assemble an example of code and post now. Vlw.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.