Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Binding to HTTPS

Tags:

.net-3.5

wcf

I understand that there are many posts about this, and I've been through all of them that came up on my search and implemented everything that was mentioned. I have a WCF web service that works on my local system on HTTP, and it worked on the server on HTTP. But the client requires that this works through HTTPS. The miriad of posts on this and other sites shows me that this is not as straight forward as it should be, since before this, the ASMX web service "just worked" and didn't need complicated configuration.

I'm getting the following error with my current configuration:

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

Here is my code as of this moment, after trying for days to configure this to work to no avail:

<system.serviceModel>

    <!--     -->
    <serviceHostingEnvironment  aspNetCompatibilityEnabled="true" >
        <baseAddressPrefixFilters>
            <add prefix="https://mysite.com"/>
            <add prefix="http://mysite.com"/>
        </baseAddressPrefixFilters>
    </serviceHostingEnvironment>

    <!-- Set up Custom Behaviors -->    
    <behaviors>

        <endpointBehaviors>
        </endpointBehaviors>

        <serviceBehaviors>
            <behavior name="WebPostService.WebPostServiceBehavior">
                <serviceMetadata httpsGetEnabled="true" httpsGetUrl="WebPostServices.svc/mex"  /> 
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>

    </behaviors>

    <!-- Set up the binding configuration  -->
    <bindings>

        <wsHttpBinding>
            <binding    name="SOAPBinding" 
            >

                <security mode="Transport">
                </security>
            </binding>
        </wsHttpBinding>

    </bindings>

    <services>

        <service    
                    behaviorConfiguration="WebPostService.WebPostServiceBehavior"
                    name="WebPostService.WebPostService"
        >

    <host>
      <baseAddresses>
        <add baseAddress="https://mysite.com/Services/WebPostService.svc"/>
      </baseAddresses>
    </host>
            <endpoint   address="" 
                        binding="wsHttpBinding" 
                        bindingConfiguration="SOAPBinding"
                        contract="WebPostService.IWebPostService"
            >
                <identity>
                    <dns value="mysite.com" />
                </identity>
            </endpoint>

            <endpoint   
                        address="mex" 
                        binding="mexHttpsBinding" 
                        contract="IMetadataExchange" 
            >
            </endpoint>

        </service>

    </services>

</system.serviceModel>

What am I doing wrong and how can I get this to work over HTTPS? I'm frustrated that this is not as simple as it should be. I have been burried in WCF documentation at MSDN for the months working on this project, and have a good grasp of services, end-points and bindings --- enough to frustrate me even more than if I had no knowledge at all.

UPDATE: Still working on this, I had an odd error when trying to put the full URL for the mex address. I changed to this:

address="https://prcwebs.com/Services/WebPostService.svc/mex" 

and got the error:

Security settings for this service require Windows Authentication but it is not enabled for the IIS application that hosts this service.

I'm not trying to use Windows Authentication, the security setting wasn't changed and is still set to

<security mode="Transport" />

Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. Registered base address schemes are [http] - was not helpful, nothing mentioned that would help Could not find a base address that matches scheme http for the endpoint with binding WSHttpBinding - I'm using transport security, this does not apply. tried changing to different security modes, still could not get site to work.

like image 514
stephenbayer Avatar asked Jan 30 '13 18:01

stephenbayer


People also ask

What is HTTP binding in WCF?

BasicHttpBinding is suitable for communicating with ASP.NET Web Service (ASMX) based services that conform to the WS-Basic Profile that conforms with Web Services. This binding uses HTTP as the transport and text/XML as the default message encoding. Security is disabled by default.

How do I enable https access for WCF RESTful service?

Add a new WebHttpBinding configuration that has security mode set to Transport . Assign that new WebHttpBinding configuration to the your Service Endpoint binding. Make sure that your RESTful service can only be accessed via HTTPS by setting httpGetEnabled="false" . Set up the metadata publishing endpoint to use HTTPS.


1 Answers

Add multipleSiteBindingsEnabled="true" to the serviceHostingEnvironment and update the security to disable client credentials:

<security mode="Transport">
    <transport clientCredentialType="None"></transport>
</security>

EDIT My final working version under windows 2003 was with the following config.

<system.serviceModel>
    <serviceHostingEnvironment  aspNetCompatibilityEnabled="false" />

    <!-- Set up Custom Behaviors -->    
    <behaviors>
        <endpointBehaviors>
        </endpointBehaviors>
        <serviceBehaviors>
            <behavior name="WebPostService.WebPostServiceBehavior">
                <serviceMetadata httpsGetEnabled="true" httpsGetUrl="WebPostServices.svc/mex"  /> 
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>

    <!-- Set up the binding configuration  -->
    <bindings>
        <wsHttpBinding>
            <binding name="SOAPBinding">
                <security mode="Transport">
                  <transport clientCredentialType="None"/>
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>

    <services>
        <service behaviorConfiguration="WebPostService.WebPostServiceBehavior"
                 name="WcfService2.Service1">

            <host>
                <baseAddresses>
                    <add baseAddress="https://localhost/Service/Service1.svc"/>
                </baseAddresses>
            </host>
            <endpoint address="" 
                      binding="wsHttpBinding" 
                      bindingConfiguration="SOAPBinding"
                      contract="WcfService2.IService1">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>

            <endpoint address="mex" 
                      binding="mexHttpsBinding" 
                      contract="IMetadataExchange">
            </endpoint>
        </service>
    </services>
</system.serviceModel>

You can access the website with https so I guess the certificate part of the installation is correct. If you have anything you want to compare with my setup, let me know.

like image 193
Luuk Avatar answered Nov 05 '22 02:11

Luuk