1

This subject is discussed several times here, but even after reading Microsoft documentation https://learn.microsoft.com/en-us/dotnet/framework/wcf/configuring-services-using-configuration-files and How can I combine the WCF services config for both http and https in one web.config?

I still do not quite get how the WCF service on all its attributes works, and can not get my service to support both protocols.

I can get the service to support either HTTP or HTTPS with no problem, the issue here is to make the service choose the correct protocol by itself.

The key point is the binding protocol on the first endpoint, any other changes like the ones shown further down had no impact.

The App.config-

<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>

The bindings -

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="AccountServicePortSoap11"/>
        <security mode="None">
          <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
          <message algorithmSuite="Default" />
        </security>
      </binding>
      <binding name="AccountServicePortSoap22" />
        <security mode="Transport">
          <transport clientCredentialType="Window" proxyCredentialType="None" realm=""/>
          <message algorithmSuite="Default" />
        </security>
      </binding>
    </basicHttpBinding>
  </bindings> 

The ending points-

<client>
       <endpoint address="" bindingConfiguration="AccountServicePortSoap11" binding="basicHttpBinding" contract="AccountServiceRef.AccountServicePort" name="AccountServicePortSoap11" />
       <endpoint address="" bindingConfiguration="AccountServicePortSoap22" binding="basicHttpBinding" contract="AccountServiceRef.AccountServicePort" name="AccountServicePortSoap22" />
</client>

Rest of App.config

  <appSettings>
    <add key="defaultServer" value="http://**.**.**.**:80 " />
  </appSettings>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="DocumentFormat.OpenXml" publicKeyToken="******" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.8.1.0" newVersion="2.8.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>  

Changes that I have tried-

<serviceBehaviors>
          <behavior name="MyServiceBehavior">
            <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
            <serviceDebug includeExceptionDetailInFaults="true" />
          </behavior>
        </serviceBehaviors>
      </behaviors>
      <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
        <protocolMapping>
    <add scheme="http"  binding="basicHttpBinding" bindingConfiguration="AccountServicePortSoap22"/>
    <add scheme="https" binding="basicHttpBinding" bindingConfiguration="AccountServicePortSoap11"/>      
  </protocolMapping>
      <services>
        <service behaviorConfiguration="MyServiceBehavior" name="com.advantage.online.store.accountservice" >
          <endpoint address="" binding="basicHttpBinding" contract="AccountServiceRef.AccountServicePort" name="AccountServicePortSoap11" />
          <endpoint address="" binding="basicHttpBinding" contract="AccountServiceRef.AccountServicePort" name="AccountServicePortSoap22" />
        </service>
      </services>
tamirShina
  • 37
  • 1
  • 7

1 Answers1

0

Generally speaking, I have the following ways to host the service over http and https.

  <system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior>
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>
<bindings>
  <webHttpBinding>
    <binding name="mybinding">
      <security mode="Transport">
        <transport clientCredentialType="None"></transport>
      </security>
    </binding>
  </webHttpBinding>
</bindings>
<protocolMapping>
  <add binding="webHttpBinding" scheme="http"/>
  <add binding="webHttpBinding" scheme="https" bindingConfiguration="mybinding"/>
</protocolMapping>    
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

Result. enter image description here I configure two endpoints which is used to support https/http respectively. By the way, I need to add https base address in IIS Site Binding module.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-configure-an-iis-hosted-wcf-service-with-ssl
Feel free to let me know if there is anything I can help with.

Abraham Qian
  • 7,117
  • 1
  • 8
  • 22
  • Our issue with this suggestion is that despite great familiarity with the code, it seems that we are unable to find the service name.. without the service name we can not define endpoints under 'service'. Finding the correct service name (if there is one) could be the solution, though there were hours of intensive search on a correct service name. – tamirShina Feb 27 '19 at 12:01
  • Do you work on the client end? What do you mean you are unable to find the service name? I noticed that you have set up the name of the service (Namespace.MyServiceClass), the contract of the service (Namespace.IServiceInterface). The interface and implemented class generally located in the wcf service project. – Abraham Qian Feb 28 '19 at 02:00
  • I work on all ends and the client end as well. Meaning of 'unable to find serviceName' being that every service name that we try to list on the app.config is unacceptable by visual studio with this error message - " the name is invalid according to its dataType 'serviceNameType". We did not write the code but I've been working on this project for several months now. – tamirShina Feb 28 '19 at 13:40
  • Try to clean and rebuild the project, then the service name will be available by intelligence sense when input the service name/service interface. Besides, I recommend you make a simply example to comprehend how to host the service over https/http referring to the above example. – Abraham Qian Mar 04 '19 at 01:44
  • you could use the simplified configuration. see the revised reply. – Abraham Qian Mar 07 '19 at 09:18
  • Thanks, my plate is currently full I'll be sure to check it out in a few days. – tamirShina Mar 10 '19 at 11:56