Monday, December 10, 2012

How to make WCF service https enabled and consume it in silverlight?

How to make WCF service https enabled and consume it in silverlight?

I have a silverlight client which currently communicates with WCF service unsecuredly.

1>I want to make WCF service secured.(https enabled) 2>I want to refer secure wcf service in silverlight client.

Can anyone help in configuring service?

Web.config :

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"></serviceHostingEnvironment>  <bindings>   <basicHttpBinding>     <binding name="MyBasicHttpBinding" >                 <security mode="Transport" >         <transport clientCredentialType="None"/>       </security>     </binding>   </basicHttpBinding> </bindings>  <services>   <service behaviorConfiguration="DataService.Service1Behavior"     name="DataService.Service1">     <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyBasicHttpBinding"       contract="DataService.IService1">              </endpoint>     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />   </service>      </services>  <behaviors>   <serviceBehaviors>     <behavior name="DataService.Service1Behavior">       <serviceMetadata httpGetEnabled="true" />       <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true" httpsHelpPageEnabled="true" />     </behavior>         </serviceBehaviors> </behaviors> 

I am getting following error message:

Could not find a base address that matches scheme https for the endpoint with binding BasicHttpBinding. Registered base address schemes are [http].

Answers & Comments...

Answer: 1

Try to add the baseAddresses section into the service element:

<services>           <service behaviorConfiguration="DataService.Service1Behavior"     name="DataService.Service1">     <host>       <baseAddresses>         <add baseAddress="https://[your url]"/>         <add baseAddress="http://[your url]"/>       </baseAddresses>     </host>     <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyBasicHttpBinding"       contract="DataService.IService1">              </endpoint>     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />   </service>      </services> 
by : Johann Blaishttp://stackoverflow.com/users/363385

Answer: 2

The main part you need to correct is binding and service behaviour as givn in following configuration

1) At the place of binding="basicHttpBinding" use binding="wsHttpBinding" 2) At the place of binding="mexHttpBinding" use binding="mexHttpsBinding" 3) In service behaviour serviceMetadata httpsGetEnabled="true"

You can find very easy steps to configure WCF on https here

by : Milan Ravalhttp://stackoverflow.com/users/485485




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog