How can I combine the WCF services config for both http and https in one web.config? -
i spent lot of time figuring out how configure wcf services work https in production environment.
basically, needed this:
<behaviors> <servicebehaviors> <behavior name="myservicebehavior"> <servicemetadata httpgetenabled="true" httpsgetenabled="true" /> <servicedebug includeexceptiondetailinfaults="true" /> </behavior> </servicebehaviors> </behaviors> <servicehostingenvironment multiplesitebindingsenabled="true" aspnetcompatibilityenabled="true" /> <services> <service name="mynamespace.myservice" behaviorconfiguration="myservicebehavior"> <endpoint address="" bindingnamespace="https://secure.mydomain.com" binding="basichttpbinding" bindingconfiguration="httpsbinding" contract="mynamespace.imyservice"/> </service> </services> <bindings> <basichttpbinding> <binding name="httpsbinding"> <security mode="transport"> <transport clientcredentialtype="none"></transport> </security> </binding> </basichttpbinding> </bindings> adding bindingnamespace attribute endpoint final thing made work.
but config doesn't work in local dev environment i'm working under regular http. config there is:
<behaviors> <servicebehaviors> <behavior name="myservicebehavior"> <servicemetadata httpgetenabled="true" httpsgetenabled="false" /> <servicedebug includeexceptiondetailinfaults="true" /> </behavior> </servicebehaviors> </behaviors> <servicehostingenvironment multiplesitebindingsenabled="true" aspnetcompatibilityenabled="true" /> <services> <service name="mynamespace.myservice" behaviorconfiguration="myservicebehavior"> <endpoint address="" binding="basichttpbinding" contract="mynamespace.imyservice"/> </service> </services> the differences here i've set httpsgetenabled attribute false, , removed bindingconfiguration , bindingnamespace.
the problem is: how create 1 config block handles both?
i hate having make lots of special modifications config every time release. yes, know have post-build task automatically changes values, i'd merge configs if possible.
i tried this:
<behaviors> <servicebehaviors> <behavior name="myservicebehavior"> <servicemetadata httpgetenabled="true" httpsgetenabled="true" /> <servicedebug includeexceptiondetailinfaults="true" /> </behavior> </servicebehaviors> </behaviors> <servicehostingenvironment multiplesitebindingsenabled="true" aspnetcompatibilityenabled="true" /> <services> <service name="mynamespace.myservice" behaviorconfiguration="myservicebehavior"> <endpoint address="" binding="basichttpbinding" contract="mynamespace.imyservice"/> <endpoint address="" bindingnamespace="https://secure.mydomain.com" binding="basichttpbinding" bindingconfiguration="httpsbinding" contract="mynamespace.imyservice"/> </service> </services> <bindings> <basichttpbinding> <binding name="httpsbinding"> <security mode="transport"> <transport clientcredentialtype="none"></transport> </security> </binding> </basichttpbinding> </bindings> i figured putting both endpoints give 2 options when activating service. however, doesn't work. error:
could not find base address matches scheme https endpoint binding basichttpbinding. registered base address schemes [http].
from looking around , rest of internet, appears others have had problems slaying dragon.
well, 1 problem combined config 2 endpoints on same address - won't work.
if you're hosting in iis, server, virtual directory , *.svc file needed determine basic address - it'll like:
http://yourservername/virtualdirectory/yourservice.svc if want have 2 endpoints, @ least 1 of them needs define relative address:
<services> <service name="mynamespace.myservice" behaviorconfiguration="myservicebehavior"> <endpoint address="basic" binding="basichttpbinding" contract="mynamespace.imyservice"/> <endpoint address="secure" binding="basichttpbinding" bindingconfiguration="httpsbinding" contract="mynamespace.imyservice"/> </service> </services> in case, you'd have http endpoint on:
http://yourservername/virtualdirectory/yourservice.svc/basic and secure https endpoint on:
https://yourservername/virtualdirectory/yourservice.svc/secure furthermore: secure endpoint uses httpsbinding configuration - you're lacking such binding configuration - have is:
<bindings> <basichttpbinding> <binding name="httpbinding"> <security mode="none"> <transport clientcredentialtype="none"></transport> </security> </binding> </basichttpbinding> </bindings> you need add httpsbinding configuration!!
<bindings> <basichttpbinding> <binding name="httpbinding"> <security mode="none"> <transport clientcredentialtype="none"></transport> </security> </binding> <binding name="httpsbinding"> <security mode="transport"> <transport clientcredentialtype="windows" /> </security> </binding> </basichttpbinding> </bindings>
Comments
Post a Comment