Code samples

There are three demo projects in the solution: ManagementDemo, EnumerationDemo and EventingDemo. First one demonstrates simple usage scenarios of plain WS-Management protocol by issuing get, put and delete requests. Second one is slightly more sophisticated. Its purpose is to show how WS-Enumeration protocol implementation behaves provided different batch size and optimize values. The last one shows simple WS-Eventing scenario where client subscribes for any event using pull delivery mode (which is the only supported mode so far).

ManagamentDemo

This application actually shows WS-Transfer protocol implementation but uses WS-Management classes to simplify interaction with native WS-Transfer. Server side consists of some code to set up WCF service host for the service and a class implementing IManagementRequestHandler interface:

   public class WsManHandler : IManagementRequestHandler
   {
      public bool CanHandle(string resourceUri)
      {
         return true;
      }

The CanHandle method is responsible for checking whether particular provider is able to handle requests targeting particular resource. This is likely to be changed in future and replaced by explicitly registering handlers for particular resource URIs.

      public object HandleGet(string fragmentExpression, IEnumerable<Selector> selectors)
      {         
         return new XmlFragment<SampleData>(new SampleData());
      }

HandleGet is invoked when client issues WS-Transfer GET request passing an expression describing which fragment of resource should be returned (fragmentExpression) and a set of so-called selector objects which provide additional info for localizing resource.

      public object HandlePut(string fragmentExpression, IEnumerable<Selector> selectors, ExtractBodyDelegate extractBodyCallback)
      {
         SampleData value = (SampleData)extractBodyCallback(typeof(SampleData));
         return value;
      }

HandlePut is invoked in response for WS-Transfer PUT. Provided arguments contain information about location of resource to be updated. extractBodyCallback delegate is used to obtain the actual sent object deserialized as provided type.

      public EndpointAddress HandleCreate(ExtractBodyDelegate extractBodyCallback)
      {         
         return new EndpointAddress("http://tempuri.org");
      }

HandleCreate is very similar to PUT, but does not include location information.

      public void HandlerDelete(IEnumerable<Selector> selectors)
      {
      }   
   }

Last edited Dec 31, 2009 at 11:03 AM by SzymonPobiega, version 2

Comments

No comments yet.