2 Replies - 1658 Views - Last Post: 02 November 2012 - 05:25 AM Rate Topic: -----

#1 abhij1987  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-May 09

how to fetch http response status code for web service ?

Posted 02 November 2012 - 04:48 AM

Hi Friends,

i have a wcf web service(.svc) and i need to write application which triggers web service after every 1 minute and find out http response status of web service, means applications calls web service and fetch web service http response status.

my main problem is i dont know how to fetch http response status code for web service ?

How i can achieve above functionality, please provide me some direction or any clue on above scenario, it will be helpful


Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: how to fetch http response status code for web service ?

#2 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: how to fetch http response status code for web service ?

Posted 02 November 2012 - 04:51 AM

You could try something like this.

Throw a HttpResponseException, which allows you to specify the response code, for example:

if (authFailed) {
    throw new HttpResponseException(HttpStatusCode.Unauthorized);
                }


Was This Post Helpful? 0
  • +
  • -

#3 abhij1987  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-May 09

Re: how to fetch http response status code for web service ?

Posted 02 November 2012 - 05:25 AM

Hi,

I have written following code.
I have created proxy class using svcutil.exe which contains ServiceClient class.
I have written timer and set 1 minute interval.
What is remaing--> i need to find out web service response, i can not change web service, but from application i need to find out http response status of web service.
main goal of this application is to find out web service is running or not.

protected void Timer1_Tick(object sender, EventArgs e)
    {

        DateTime starttime,Endtime;
        starttime = DateTime.Now;
        Nullable<DateTime> response = null;
        bool  result=false;
        try
        {
            
            ServiceClient ob1 = new ServiceClient();
            response=ob1.GetStatus("para1");
          
            Endtime = DateTime.Now;
            insertintoDB(starttime, Endtime, response.ToString());
        }
        catch (Exception ex)
        {
            string response1;
             Endtime = DateTime.Now;
             response1 = " Message:-"+ ex.Message.ToString() + " StackTrace:- " + ex.StackTrace + " InnerException:-" + ex.InnerException + " Source:-" + ex.Source;
             insertintoDB(starttime, Endtime, response1);
        }
    }

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1