【问题标题】:Cannot get WCF resful service to use https/ssl无法获得 WCF 宁静服务以使用 https/ssl
【发布时间】:2015-08-11 17:41:48
【问题描述】:

我知道过去曾有过这个问题的答案,但是在经历了很多之后我仍然遇到问题,所以我希望有人可以查看这个配置并告诉我它的去向错了……

这是我正在部署的自托管 rest WCF 服务的配置:

<?xml version="1.0" encoding="utf-8" ?>
    <configuration>

        <appSettings>
            <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
        </appSettings>
        <system.web>
            <customErrors mode="Off"/>    
            <compilation debug="true" />
        </system.web>

        <system.serviceModel>
            <services>
                <service name="SampleService.SampleService" behaviorConfiguration="ServiceBehavior" >
                    <endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpTransportSecurity" behaviorConfiguration="web" contract="SampleService.ISampleService"/>
                    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
                </service>
            </services>
            <bindings>
                <webHttpBinding>
                    <binding name="webHttpTransportSecurity">
                        <security mode="Transport" >
                            <transport clientCredentialType="None" proxyCredentialType="None" />
                        </security>
                    </binding>
                </webHttpBinding>
            </bindings>   
            <behaviors>
                <endpointBehaviors>
                    <behavior name="web">
                        <webHttp />
                    </behavior>
                </endpointBehaviors>
                <serviceBehaviors>
                    <behavior name="ServiceBehavior">
                        <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false"/>
                        <serviceDebug includeExceptionDetailInFaults="false"/>
                    </behavior>
                </serviceBehaviors>
            </behaviors>
            <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
        </system.serviceModel>
    </configuration>

服务器上的错误表明该服务想要使用 http 而不是 https,我终生无法弄清楚配置有什么问题。在一天中的大部分时间里,我已经完成了它。这是一个相对微不足道的小服务。

【问题讨论】:

  • 为什么将clientCredentialTypeproxyCredentialType 设置为"None" on the ` 元素?这不是违背了目的吗?
  • 无 指定匿名身份验证。我不想让用户提示输入用户名/密码。

标签: web-services wcf azure wcf-rest


【解决方案1】:

您的服务元素中的服务端点地址是相对,这意味着它们相对于您的服务的基地址。默认情况下,基地址使用 http 方案,这是您的服务正在使用的。 因此,如果您的基址是http://localhost/myservice,那么您的两个端点将是http://localhost/myservicehttp://localhost/myservice/mex

您可以通过包含方案 (https) 和完整的 Uri 来使您的端点地址绝对。例如,“https://localhost/myservice”和“https://localhost/myservice/mex”而不是像现在这样的“”和“mex”。

或者,您可以像这样向使用 https 方案的服务添加基地址。

<host>
  <baseAddresses>
    <add baseAddress="https://localhost/myservice"/>
  </baseAddresses>
</host>

这假设您已注册 SSL 证书以支持传输安全。如果你还没有,那么你也需要这样做。

作为旁注,我建议将 ASP.NET Web API 用于 RESTful Web 服务而不是 WCF。 Here is a brief intro 如果您不熟悉它,可以帮助您入门。

【讨论】:

  • 嘿 Rick,我也更喜欢使用 Web API,不幸的是我正在处理的项目决定使用 WCF,我有点坚持。
  • 所以是的,我确实配置了 ssl,并且托管站点本身(云服务)是安全的。只是当我尝试访问网站上的服务时,我遇到了这个问题。
  • 这是网络角色?
  • 确实是网络角色。很抱歉没有在描述中提供完整的图片。
  • 您是否将云服务上的端点配置为使用 SSL?我在这里展示了如何为传统的 WCF 端点(不是 webHttp)执行此操作。 rickrainey.com/2013/09/18/… 但是,我相信云服务上的配置是一样的。
【解决方案2】:

不幸的是,这再次提醒我,除非我非常确定它是如何设置的,否则我不应该尝试拼凑来自第三方的原型代码。从头开始会更好(我最终这样做了)。事实证明,我的配置方式完全有效,但解决方案中的 azure 服务打包和部署过程格式不正确。

很抱歉浪费了带宽,感谢所有试图帮助我的人。

【讨论】:

    猜你喜欢
    • 2014-04-06
    • 1970-01-01
    • 2019-08-30
    • 1970-01-01
    • 2012-11-14
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多