2014-11-15 86 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用於持久性。採取適應文本質量的自由。 –