How to Configuring WCF services to work with both HTTP and HTTPS

898 views Asked by At

Iam trying to configure a service for access over both https and http from a silverlight 4 application. I am able to access the service over https but not over http. I have made some research over the net but can't seem to get the configuration right.

Below is my current settings in the my web.config file.

    <system.serviceModel>

    <bindings>
      <customBinding>
          <binding name="MyhttpsBinding">
          <binaryMessageEncoding/>
          <httpsTransport/> 
          </binding>
          <binding name="MyhttpBinding">
              <binaryMessageEncoding/>
              <httpTransport/>
          </binding>
      </customBinding>
    </bindings>

    <services>
      <service name="MyData" behaviorConfiguration="MyData">
        <endpoint address="" binding="customBinding" bindingConfiguration="MyData.customBinding.https" contract="MyData"/>
        <endpoint address="" binding="customBinding" bindingConfiguration="MyData.customBinding.http" contract="MyData"/>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="MyData" >
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
        </behavior>
        <behavior name="">
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
  </behaviors>

  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>

And below is my ServiceReferences.ClientConfig file

<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="DataS" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
            <binding name="DataS1" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
        </basicHttpBinding>
        <customBinding>
            <binding name="CustomBinding_GetData">
                <binaryMessageEncoding />
                <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
            </binding>
        </customBinding>
    </bindings>

    <client>
        <endpoint address="//localhost/MyApp/Webservice/Data.asmx"
            binding="basicHttpBinding" bindingConfiguration="DataS1"
            contract="ServiceReference1.DataS" name="DataS" />

        <endpoint address="//localhost/MyApp/Webservice/GetData.svc"
            binding="customBinding" bindingConfiguration="CustomBinding_GetData"
            contract="GetData.GetData" name="CustomBinding_GetData" />
    </client>

</system.serviceModel>

What do i have mis-configured above that is making the calls to the service fail on http.

1

There are 1 answers

10
Vinod Kumar On

Add one more endpoint with mexHttpBinding as below endpoint address="mexhttp" binding="mexHttpBinding" contract="IMetadataExchange"/>

and also

add the service behavior to the service tag

<service name="MyData" behaviorConfiguration="MyData">