简体   繁体   中英

WCF web service returning 404 over HTTPS but works over HTTP

I've got a web service written years ago that works fine over http. It works via a web browser to see the service description and it responds correctly to soap calls. We now want to move it over to https.

I've made some changes to the web.config file to try and enable it to work over https. I can now call it via https in a browser and see the service description but I cannot call the web service using a soap call via https - I get a 404 error.

I am testing the soap calls by using Postman, so this seems to indicate the issue is either with the web.config or IIS.

I've found many posts with issues relating to WCF over https but as yet have not been successful at resolving this. Any help would be greatly appreciated.

Service related code from web.config shown below.

<system.serviceModel>
    <services>
  <service name="EComAPI" behaviorConfiguration="WCFAuthBehavior">
    <endpoint address="soap" binding="wsHttpBinding" contract="IEComAPI" bindingConfiguration="httpbinding1"></endpoint>
    <endpoint address="soap" binding="wsHttpBinding" contract="IEComAPI" bindingConfiguration="httpsbinding1"></endpoint>
    <endpoint address="rest" binding="webHttpBinding" contract="IEComAPI" behaviorConfiguration="rest" bindingConfiguration="httpbinding2"></endpoint>
    <endpoint address="rest" binding="webHttpBinding" contract="IEComAPI" behaviorConfiguration="rest" bindingConfiguration="httpsbinding2"></endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
  </service>
</services>

    <bindings>
      <wsHttpBinding>
        <binding name="httpbinding1">
          <security mode="None"></security>
        </binding>
        <binding name="httpsbinding1">
          <security mode="Transport">
            <transport clientCredentialType="None"></transport>
          </security>
        </binding>
      </wsHttpBinding>

      <webHttpBinding>
        <binding name="httpbinding2">
          <security mode="None">
          </security>
        </binding>
        <binding name="httpsbinding2">
          <security mode="Transport">
            <transport clientCredentialType="None"></transport>
          </security>
        </binding>
      </webHttpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior name="WCFAuthBehavior">
          <serviceMetadata httpsGetEnabled="false" httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior name="">
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="rest">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

In summary:

  • http web request to this service - ok
  • http soap request to this service - ok

  • https web request to this service - ok

  • https soap request to this service - gives a 404

If we want to call the service with SOAP style over HTTPS, we should use Wshttpbinding to publish the service endpoint and specify the client credential type(default value is windows).

    <system.serviceModel>
      <services>
        <service name="VM1.MyService" behaviorConfiguration="mybehavior">
          <endpoint address="" binding="wsHttpBinding" contract="VM1.IService" bindingConfiguration="mybinding"></endpoint>
          <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"></endpoint>
        </service>
      </services>
      <bindings>
        <wsHttpBinding>
          <binding name="mybinding">
            <security mode="Transport">
              <transport clientCredentialType="None"></transport>
            </security>
          </binding>
        </wsHttpBinding>
      </bindings>
      <behaviors>
        <serviceBehaviors>
          <behavior name="mybehavior">
            <serviceMetadata />
          </behavior>
        </serviceBehaviors>
      </behaviors>
</system.serviceModel>

Then specify an https endpoint in IIS site binding module.
If we want to publish the service with Restful style, we should use WebHttpBinding.
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/wcf-web-http-programming-model
At last, I have made a similar configuration which supports both SOAP style and Restful style(required that add the webget/webinvoke to operation method), and it support both https and http.

<system.serviceModel>
      <services>
        <service name="VM1.MyService" behaviorConfiguration="mybehavior">
          <endpoint address="soap” binding="wsHttpBinding" contract="VM1.IService" bindingConfiguration="httpbinding1"></endpoint>
          <endpoint address="soap” binding="wsHttpBinding" contract="VM1.IService" bindingConfiguration="httpsbinding1"></endpoint>
          <endpoint address="rest” binding="webHttpBinding" contract="VM1.IService" behaviorConfiguration="rest" bindingConfiguration="httpbinding2"></endpoint>
          <endpoint address="rest” binding="webHttpBinding" contract="VM1.IService" behaviorConfiguration="rest" bindingConfiguration="httpsbinding2"></endpoint>
          <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" ></endpoint>
        </service>
      </services>
      <bindings>
        <wsHttpBinding>
          <binding name="httpbinding1">
            <security mode="None"></security>
          </binding>
          <binding name="httpsbinding1">
            <security mode="Transport">
              <transport clientCredentialType="None"></transport>
            </security>
          </binding>
        </wsHttpBinding>
        <webHttpBinding>
          <binding name="httpbinding2">
            <security mode="None">
            </security>
          </binding>
          <binding name="httpsbinding2">
            <security mode="Transport">
              <transport clientCredentialType="None"></transport>
            </security>
          </binding>
        </webHttpBinding>
      </bindings>
      <behaviors>
        <serviceBehaviors>
          <behavior name="mybehavior">
            <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
          <behavior name="rest">
            <webHttp />
          </behavior>
        </endpointBehaviors>
      </behaviors>
    </system.serviceModel>

Please don't forget the specify the Http and Https base address in IIS site binding module provided that we host the service in IIS.
Feel free to let me know if there is anything I can help with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM