I would like to programmatically change the binding and behavior for web services on the server. I have two sets of bindings and behaviors – 1 for localHost and another for the server that we deploy to. I have to comment out one, and uncomment the other each time we deploy.
On the Silverlight client, I have code that I run each time I setup the web service client. This code changes the binding and endpoint as needed. However, I cannot figure out how to do this on the server.
I assume I need to put the code in global.asax on Application_Start. However, I cannot figure out how to read the bindings and change them.
At the bottom of this post you will see the web.config settings. I have two bindings both named DefaultBinding, and two behaviors both name DefaultBehavior. I comment out the one that is not needed. However, I would like to only have one and change it at runtime.
The code below seems to read the web.config entries and I can change them. However, they are not saved. If I read them from web.config again I have the web.config values – not what I changed it to.
System.ServiceModel.Configuration.BasicHttpBindingElement binding = new System.ServiceModel.Configuration.BasicHttpBindingElement("DefaultBinding"); binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.None; binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Certificate;
I want to avoid having to change the config file each time I deploy. I appreciate any advice; either how to solve these issues, or another approach for soling this issue. I have been researching the issue but everything I find is related to the client not the server.
Here are my web.config entries:
<system.serviceModel> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /> <services> <service name="UserInfo" behaviorConfiguration="DefaultBehavior"> <endpoint address="mex" binding="basicHttpBinding" bindingConfiguration="DefaultBinding" contract="name="UserInfo" " /> </service> </services> <bindings> <basicHttpBinding> <!--start for the server--> <!--<binding name="DefaultBinding"> <security mode="Transport"> <transport clientCredentialType="None"> </transport> </security> </binding>--> <!--end for the server--> <!--start for localhost--> <binding name="DefaultBinding"> <security mode="None"> <transport clientCredentialType="Certificate"> </transport> </security> </binding> <!--end for localhost--> </basicHttpBinding> </bindings> <behaviors> <serviceBehaviors> <!--start for the server--> <!--<behavior name="DefaultBehavior"> <serviceMetadata httpsGetEnabled="true" /> </behavior>--> <!--end for the server--> <!--start for localhost--> <behavior name="DefaultBehavior"> <serviceMetadata httpGetEnabled="true" /> </behavior> <!--end for loalhost--> </serviceBehaviors> </behaviors> </system.serviceModel>
Answer: 1
You can set both http and https bindings up in your web.config service configurations then there should be node need to cahnge them at runtime. See my post here for an example:
by :
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog