简体   繁体   English

WCF Web服务通过HTTPS返回404,但通过HTTP起作用

[英]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. 几年前,我有一个Web服务可以在http上正常运行。 It works via a web browser to see the service description and it responds correctly to soap calls. 它可以通过Web浏览器查看服务说明,并且可以正确响应肥皂呼叫。 We now want to move it over to https. 现在,我们要将其移至https。

I've made some changes to the web.config file to try and enable it to work over https. 我对web.config文件进行了一些更改,以尝试使其能够通过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. 现在,我可以在浏览器中通过https调用它,并查看服务说明,但是我无法使用通过https进行的肥皂调用来调用Web服务-我收到404错误。

I am testing the soap calls by using Postman, so this seems to indicate the issue is either with the web.config or IIS. 我正在使用Postman测试肥皂呼叫,因此这似乎表明问题出在web.config或IIS。

I've found many posts with issues relating to WCF over https but as yet have not been successful at resolving this. 我发现许多帖子都涉及到与https上的WCF有关的问题,但到目前为止尚未成功解决。 Any help would be greatly appreciated. 任何帮助将不胜感激。

Service related code from web.config shown below. 来自web.config的服务相关代码如下所示。

<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 Web请求-好的
  • http soap request to this service - ok 对此服务的http soap请求-确定

  • https web request to this service - ok https对此服务的Web请求-确定

  • https soap request to this service - gives a 404 对该服务的https soap请求-给出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). 如果要通过HTTPS以SOAP样式调用服务,则应使用Wshttpbinding发布服务端点并指定客户端凭据类型(默认值为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. 然后在IIS网站绑定模块中指定一个https终结点。
If we want to publish the service with Restful style, we should use WebHttpBinding. 如果要以Restful样式发布服务,则应使用WebHttpBinding。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/wcf-web-http-programming-model https://docs.microsoft.com/zh-cn/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. 最后,我做了一个类似的配置,它同时支持SOAP样式和Restful样式(要求将webget / webinvoke添加到操作方法中),并且它同时支持https和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. 如果我们在IIS中托管服务,请不要忘记在IIS网站绑定模块中指定Http和Https基地址。
Feel free to let me know if there is anything I can help with. 请随时告诉我是否有什么我可以帮助的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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