Performing control action

As in the case for the /Momentary resource, we check the Accept header to see how the client wants the response to be represented. If no such header is available, we will assume XML is requested. If an unrecognized content type is requested, we make sure to return a 406 Not Acceptable response before we perform the control action:

if (req.Header.Accept != null) 
{ 
   switch (req.Header.Accept.GetBestContentType("text/xml", 
         "application/xml", "application/json")) 
   { 
         case "text/xml": 
         case "application/xml": 
               await this.SetOutput(OutputValue, 
                     req.RemoteEndPoint); 
               this.ReturnMomentaryAsXml(req, resp); 
               break; 
 
         case "application/json": 
               await this.SetOutput(OutputValue, 
                     req.RemoteEndPoint); 
               this.ReturnMomentaryAsJson(req, resp); 
               break; 
 
         default: 
               throw new NotAcceptableException(); 
   } 
} 
else 
{ 
   await this.SetOutput(OutputValue, req.RemoteEndPoint); 
   this.ReturnMomentaryAsXml(req, resp); 
} 

Here, we reuse the content serialization methods defined for the /Momentary resource. But since the resource is defined as an asynchronous resource, it will actually not be sent, or completely sent, until the resp.SendResponse(); is called.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset