2014-11-15 81 views
2

根据wisdom of the Internet,如果我打算将我的网站托管为东西(例如我),则安全模式已被激活。但是,当我拨打下面的(1)时,我得到404 - 资源找不到,而(2)的调用导致预期的行为。这两行之间的唯一区别是协议的安全级别(复制粘贴它两次!),所以我质疑提供的链接的真实性。如何启用我的Azure网站作为https而不是http?

  1. https://one-of-my.azurewebsites.net/SomeService.svc/Tester/beep
  2. http://one-of-my.azurewebsites.net/SomeService.svc/Tester/beep

我能做些什么?

但是,我也注意到:

https://one-of-my.azurewebsites.net/SomeService.svc

给我常用的部位,这样可能与在方法定义本身事做。它看起来有点像这样。

namespace One-of-my 
{ 
    [ServiceContract(Namespace = "")] 
    [AspNetCompatibilityRequirements(RequirementsMode 
    = AspNetCompatibilityRequirementsMode.Allowed)] 
    public class SomeService 
    { 
    [OperationContract] 
    [WebGet(
     UriTemplate = "Tester/{blopp}", 
     ResponseFormat = WebMessageFormat.Json)] 
    public async Task<String> Tester(String blopp) { ... } 
    } 
} 

我的配置如下所示。第一个system.serviceModel

<system.serviceModel> 
    <services> 
    <service name="MySite.MyService"> 
     <endpoint address="" 
     behaviorConfiguration="MySite.MyServiceAspNetAjaxBehavior" 
     binding="webHttpBinding" 
     contract="MySite.MyService" /> 
    </service> 
    </services> 
    <behaviors> 
    <endpointBehaviors> 
     <behavior name="MySite.MyServiceAspNetAjaxBehavior"> 
     <webHttp/> 
     </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
     <behavior name=""> 
     <serviceMetadata 
      httpGetEnabled="true" 
      httpsGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 
    <protocolMapping> 
    <add binding="basicHttpsBinding" scheme="https" /> 
    </protocolMapping> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
    multipleSiteBindingsEnabled="true" /> 
</system.serviceModel> 

这里,system.webServer

<system.webServer> 
    <httpProtocol> 
    <customHeaders> 
     <add name="Access-Control-Allow-Origin" value="*" /> 
     <add 
     name="Access-Control-Allow-Methods" 
     value="GET,POST,DELETE,HEAD,PUT,OPTIONS" /> 
     <add 
     name="Access-Control-Allow-Headers" 
     value="X-Olaround-Debug-Mode, Authorization, Accept" /> 
     <add 
     name="Access-Control-Expose-Headers" 
     value="X-Olaround-Debug-Mode, X-Olaround-Request-Start-Timestamp, 
      X-Olaround-Request-End-Timestamp, X-Olaround-Request-Time, 
      X-Olaround-Request-Method, X-Olaround-Request-Result, 
      X-Olaround-Request-Endpoint" /> 
    </customHeaders> 
    </httpProtocol> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    <directoryBrowse enabled="true"/> 
</system.webServer> 
+1

你能告诉我们你的WCF服务配置从web.config? – b2zw2a

+0

@plentysmart是的。请查看原始帖子中的修改。 –

+0

@plentysmart除了上面显示的添加,我也感觉到[这个答案](http://stackoverflow.com/a/16387355/1525840)触及我的问题。但是,我不知道如何使用它,因为我不在使用服务器的设置,因为我使用的是Azure。 –

回答

1

您必须添加绑定配置<security mode="Transport" />。 所以你的配置应该看起来像这样(首先是做这个技巧的部分)。

<bindings> 
    <webHttpBinding> 
    <binding name="HttpsConfiguration"> 
     <security mode="Transport" /> 
    </binding> 
    </webHttpBinding> 
</bindings> 

接下来是整个文件架构。

<system.serviceModel> 
    <bindings> ... </bindings> 
    <services> ... </services> 
    <behaviors> ... </behaviors> 
    ... 
</system.serviceModel> 

我试过这个配置(与我的WCF服务名称&合同)并能正常工作都在http & HTTPS。

+0

+1用于持久性。采取适应文本质量的自由。 –