Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF - how to set "enableWebScript" dynamically?
    text
    copied!<p>I'm working on my first WCF service, which will support several Ajax calls. I have an endpoint configured this way:</p> <pre><code> &lt;service behaviorConfiguration="ServiceBehavior" name="AQM"&gt; &lt;endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="Binding1" contract="IAQM" /&gt; &lt;/service&gt; </code></pre> <p>and my behavior configuration:</p> <pre><code> &lt;endpointBehaviors&gt; &lt;behavior name="web"&gt; &lt;webHttp /&gt; &lt;enableWebScript /&gt; &lt;/behavior&gt; &lt;/endpointBehaviors&gt; </code></pre> <p>I need to create my own error handling so that I can format some specific information back to the client (see here <a href="http://zamd.net/2008/07/08/error-handling-with-webhttpbinding-for-ajaxjson/" rel="nofollow">http://zamd.net/2008/07/08/error-handling-with-webhttpbinding-for-ajaxjson/</a>). My WebServiceHostFactory looks like this:</p> <pre><code>public class MyServiceFactory : WebServiceHostFactory { public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses) { var sh = new ServiceHost(typeof(AQM), baseAddresses); sh.Description.Endpoints[0].Behaviors.Add(new WebHttpBehaviorEx()); return sh; } protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) { return base.CreateServiceHost(serviceType, baseAddresses); } } public class WebHttpBehaviorEx : WebHttpBehavior { protected override void AddServerErrorHandlers(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { // Clear default error handlers endpointDispatcher.ChannelDispatcher.ErrorHandlers.Clear(); // Add our own error handler endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(new ErrorHandlerEx()); } </code></pre> <p>However, after I created my own error handler, it seems it overrides the "enableWebScript" setting I had in my config above, which I think makes sense because now I'm creating my very own behavior dynamically which doesn't have any of the config settings above. </p> <p>I read that this setting should be used with WCF/Ajax for security purposes (see here <a href="http://www.asp.net/ajaxlibrary/Using%20JSON%20Syntax%20with%20Ajax.ashx" rel="nofollow">http://www.asp.net/ajaxlibrary/Using%20JSON%20Syntax%20with%20Ajax.ashx</a>). So my question is, how can I set the the "enableWebScript" setting on my dynamically created behavior? Or is it not possible? </p> <p>Update (6/1/2011): I'm also looking to dynamically change the behavior to use Windows credentials for authentication. In the config file it's done like this:</p> <pre><code>&lt;bindings&gt; &lt;webHttpBinding&gt; &lt;binding name="Binding1"&gt; &lt;security mode="TransportCredentialOnly"&gt; &lt;transport clientCredentialType="Windows" /&gt; &lt;/security&gt; &lt;/binding&gt; &lt;/webHttpBinding&gt; &lt;/bindings&gt; </code></pre> <p>This is another setting I need to make programmatically since it seems to ignore the config setting.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload