Configuring a service to serve http and https is become a common requirement for all the services. I have spent googling on this. After spending about 6 hours I fincdout below one would configure your service for both http and https.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="httpsConfiguration" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<security mode="Transport">
<transport clientCredentialType ="None"/>
</security>
</binding>
<binding name="httpConfiguration" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceBehavior" name="YourServiceName">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="httpsConfiguration" contract="YourServiceContract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="httpConfiguration" contract="YourServiceContract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="httpsConfiguration" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<security mode="Transport">
<transport clientCredentialType ="None"/>
</security>
</binding>
<binding name="httpConfiguration" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceBehavior" name="YourServiceName">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="httpsConfiguration" contract="YourServiceContract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="httpConfiguration" contract="YourServiceContract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Nice work, your blog is concept-oriented, kindly share more blogs like this
ReplyDeleteDot NET Online Training Hyderabad