jeudi 28 janvier 2016

Make No Response status for http calls

I have implement Get() for http get requests. And I am making a rest call to that function with some authentication headers. When supplied with valid authentication headers, it works. But When I use invalid header, I should get "No Response" in my rest client. This needs to implement. Could anyone say what should do for this. I am using DHC ReST client chrome extension as my Rest client. Given below the GET implementation

public stream Get()
{
  if(WebOperationContext.Current.IncomingRequest.Headers.AllKeys.Contains("Authorization"))
  {
    //Validating the header
    ...
    if( valid header)
    {
       WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml";
       byte[] bytes = Encoding.UTF8.GetBytes(xml);
       var stream = new MemoryStream(bytes);

       stream.Seek(0, SeekOrigin.Begin);
       return stream;
    }

    if(invalid header)
    {
      //I need to handle the no resposen code here.
      //I tried, throw exception, change status code, return null stream but nothing worked.
    }
  }
}




Aucun commentaire:

Enregistrer un commentaire