Skip to content

Instantly share code, notes, and snippets.

@samoshkin
Created November 2, 2011 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samoshkin/1333273 to your computer and use it in GitHub Desktop.
Save samoshkin/1333273 to your computer and use it in GitHub Desktop.
Adding operations to WCF service on runtime
public static OperationDescription[] AddHelpOperations(ContractDescription contractDescription, DispatchRuntime dispatchRuntime)
{
Fx.Assert(contractDescription != null, "The 'contractDescription' parameter should not be null.");
Fx.Assert(dispatchRuntime != null, "The 'dispatchRuntime' parameter should not be null.");
Uri baseAddress = dispatchRuntime.EndpointDispatcher.EndpointAddress.Uri;
HelpPage helpPage = new HelpPage(baseAddress, null, contractDescription);
HttpOperationDescription helpPageOperation = new HttpOperationDescription(HelpPage.HelpMethodName, contractDescription);
helpPageOperation.Behaviors.Add(new WebGetAttribute() { UriTemplate = HelpPage.OperationListHelpPageUriTemplate });
helpPageOperation.InputParameters.Add(HttpParameter.RequestMessage);
helpPageOperation.ReturnValue = HttpParameter.ResponseMessage;
HttpOperationDescription operationhelpPageOperation = new HttpOperationDescription(HelpPage.HelpOperationMethodName, contractDescription);
operationhelpPageOperation.Behaviors.Add(new WebGetAttribute() { UriTemplate = HelpPage.OperationHelpPageUriTemplate });
operationhelpPageOperation.InputParameters.Add(HttpParameter.RequestMessage);
operationhelpPageOperation.InputParameters.Add(new HttpParameter("operation", TypeHelper.StringType));
operationhelpPageOperation.ReturnValue = HttpParameter.ResponseMessage;
dispatchRuntime.Operations.Add(
new DispatchOperation(dispatchRuntime, HelpPage.HelpMethodName, null, null) { Invoker = helpPage.GetHelpPageInvoker(true) });
dispatchRuntime.Operations.Add(
new DispatchOperation(dispatchRuntime, HelpPage.HelpOperationMethodName, null, null) { Invoker = helpPage.GetHelpPageInvoker(false) });
return new OperationDescription[] { helpPageOperation.ToOperationDescription(), operationhelpPageOperation.ToOperationDescription() };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment