Configure HttpOperationHandlerFactory in Global asax in wcf web api6

Topics: Web Api
Feb 6, 2012 at 12:39 PM

I have Created my Custom OperationHandler factory and define multiple operation hanlder to handle the input request.

 

 

public class MyOperationHandlerFactory :HttpOperationHandlerFactory 

{

protected override Collection<HttpOperationHandler> OnCreateRequestHandlers(ServiceEndpoint endpoint, HttpOperationDescription operation)

{

 

 

var coll = base.OnCreateRequestHandlers(endpoint, operation);

 switch (operation.Name)

{

 

case "QueryCustomerNumbers":

coll.Add(new QueryCustomerNumbersAsParameterHandler());

 break;

 case "DeleteIdentity":

coll.Add(new DeleteIdentityAsParameterHandler());

 break;

}

}

}

 

public class QueryCustomerNumbersAsParameterHandler : HttpOperationHandler<string, string, string, string,GetCustomerNumberRequest>

{

 

public QueryCustomerNumbersAsParameterHandler()

:

base("request")

{

}

protected override GetCustomerNumberRequest OnHandle(string claimValue,string claim, string provider,string namedIdentity )

{if (!string.IsNullOrEmpty(provider)) if (!Enum.IsDefined(typeof(IdentityProviders), provider))

provider =null;

 if (!string.IsNullOrEmpty(claim)) if (!Enum.IsDefined(typeof(Claim), claim))

claim =null;

 return new GetCustomerNumberRequest {NamedIdentity =namedIdentity, Value = claimValue, Claim = string.IsNullOrEmpty(claim) ? Claim.NotSet : (Claim)Enum.Parse(typeof(Claim), claim), IdentityProvider = string.IsNullOrEmpty(provider) ? IdentityProviders.NotSet : (IdentityProviders)Enum.Parse(typeof(IdentityProviders), provider) };

}

}

 

public class DeleteIdentityAsParameterHandler : HttpOperationHandler<string, string,DeleteIdentityReq>
 
 

{ publicDeleteIdentityAsParameterHandler()

:base("request")

{}

 protected override DeleteIdentityReq OnHandle(string provider, string namedIdentity)

{

 

if (!string.IsNullOrEmpty(provider)) if (!Enum.IsDefined(typeof(IdentityProviders), provider))

provider =null;

   

 

 

}

}

return new DeleteIdentityReq { NamedIdentity = namedIdentity, IdentityProvider = string.IsNullOrEmpty(provider) ? IdentityProviders.NotSet : (IdentityProviders)Enum.Parse(typeof(IdentityProviders), provider) };





Configuration in  Global Asax



var kernel = BuildKernel();

 

var config = HttpHostConfiguration.Create().SetOperationHandlerFactory(kernel.Get(typeof(MyOperationHandlerFactory)) as MyOperationHandlerFactory).SetResourceFactory(new injectResourceFactory(kernel)).SetErrorHandler<SecurityServiceErrorHandler ();

 

Now as per new enhancement this HttpHostConfiguation in not available in webapi6.Fr that WebapiConfiguration is used

 

 

  

var

 

 

dd = new WebApiConfiguration

()

{

 

EnableTestClient =

 

true

 

};

 

 So i want to know how to configure HttpOperationHandler  factory in global asax .

 

 

Thanks in Advance 

 

return coll;

Feb 6, 2012 at 4:28 PM

Just looking at the available classes, it looks like you need to derive from Microsoft.ApplicationServer.Http.WebApiHttpOperationHandlerFactory.  After you do that, you should be able to assign the handlers like:

dd.RequestHandlers = myOperationHandlerFactory.RequestHandlerDelegate;
dd.ResponseHandlers = myOperationHandlerFactory.ResponseHandlerDelegate;

(using your variable names, of course)

Feb 7, 2012 at 9:20 AM

Thanks Davi for reply.

i have implmented the  code which u have mention :

dd.RequestHandlers = myOperationHandlerFactory.RequestHandlerDelegate;
dd.ResponseHandlers = myOperationHandlerFactory.ResponseHandlerDelegate;

 

i have inherit the WebApiHttpOperationHandlerFactory in MyOperationHandlerFacoty class.

 

But myOperationHandlerFactory factory does now show any propety with the name of RequestHandlerDelegate or ResponseHandlerDelegate.

Feb 7, 2012 at 4:26 PM

Make sure you're using the latest release.  It's there.

Feb 8, 2012 at 9:55 AM
Edited Feb 8, 2012 at 11:58 AM

i have implmented the  code which u have mention :

dd.RequestHandlers = myOperationHandlerFactory.RequestHandlerDelegate;
dd.ResponseHandlers = myOperationHandlerFactory.ResponseHandlerDelegate;

 

i have inherit the WebApiHttpOperationHandlerFactory in MyOperationHandlerFacoty class.

 

ANd Configured in Global Asax. but its not working..

Feb 8, 2012 at 3:22 PM

Sorry, I've not personally tried it and may in fact be wrong in my guidance.  I just looked at the classes/method sigantures and that looked like it might work.  You should probably look at the source and see how it actually works.

Feb 8, 2012 at 4:26 PM

I can't understand your code. If you gave a link to a zip I could help you.