2012-06-17 84 views
3

在https站點中訪問我的Web服務期間,我遇到了一個錯誤。 我認爲這是一個配置錯誤,因爲它尋找一個https綁定。如何爲Ajax配置HTTPS和HTTP綁定已啓用WCF Web服務

這裏是Web服務的web.config文件:

<?xml version="1.0"?> 
<configuration> 
<system.serviceModel> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/> 
<services> 
    <service name="WebService.ListViewWebService" behaviorConfiguration="WebService.ListViewWebServiceBehavior"> 
    <endpoint address="" 
       behaviorConfiguration="WebService.ListViewWebServiceAjaxBehavior" 
       binding="webHttpBinding" 
       contract="WebService.IListViewWebService"/> 
    <endpoint address="https://win-d741qhlbivf:13241/services/DPT/_vti_bin/DPT.WebService/ListViewWebService.svc" 
       behaviorConfiguration="WebService.ListViewWebServiceAjaxBehavior1" 
       binding="webHttpsBinding" 
       contract="WebService.IListViewWebService2"/> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />   
    </service> 
</services> 
<bindings> 
    <basicHttpBinding> 
     <binding name="webHttpBinding"> 
      <security mode="None" /> 
     </binding> 
     <binding name="webHttpsBinding"> 
      <security mode="Transport" /> 
     </binding> 
    </basicHttpBinding> 
</bindings> 
<behaviors> 
    <endpointBehaviors> 
    <behavior name="WebService.ListViewWebServiceAjaxBehavior"> 
     <webHttp/> 
    </behavior> 

    </endpointBehaviors> 
    <serviceBehaviors> 
    <behavior name="WebService.ListViewWebServiceBehavior"> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
     <serviceMetadata httpGetEnabled="true" /> 
    </behavior> 

    </serviceBehaviors> 
</behaviors> 
</system.serviceModel> 
</configuration> 

感謝提前的幫助。

另外,我不知道這有什麼做的問題,而是在雲環境中託管Web應用程序......我需要一個特殊的配置是什麼?...再次

感謝。 。

回答

1

我的一個教程將幫助您:

http://netpl.blogspot.com/2010/05/how-to-programmatically-configure-ssl.html

教程與聲明的配置開始,然後展示瞭如何以編程方式創建綁定/端點。

+0

嗨,謝謝你的回覆。我在你的博客中按照你的步驟,但我得到了同樣的錯誤: – GeekInPurpleAndPink

+0

錯誤是:沒有名爲'WebService.ListViewWebServiceAjaxBehavior1'的終端行爲。 (C:\ Program Files \ Common Files \ Microsoft Shared \ Web Server Extensions \ 14 \ isapi \ webservice \ web.config line 11) – GeekInPurpleAndPink

+0

請參閱我的更新,以獲取新的配置:)謝謝 – GeekInPurpleAndPink

0

這個配置將在HTTP和HTTPS請求作出響應,請注意端口是不同的,有以匹配主機期待(在這種情況下,它碰巧是IIS)

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

     <customErrors mode="Off"/> 
    </system.web> 



<system.serviceModel> 
    <serviceHostingEnvironment minFreeMemoryPercentageToActivateService="0" /> 

    <services> 
     <service name="KPIGetter_Library.KPIGetter"> 

      <endpoint address="" 
        behaviorConfiguration="restfulBehaviour" 
        binding="webHttpBinding" 
        bindingConfiguration="webHttpBindingWithJsonP" 
        contract="KPIGetter_Library.IKpiGetter" /> 


      <endpoint address="" 
        behaviorConfiguration="restfulBehaviour" 
        binding="webHttpBinding" 
        bindingConfiguration="webHttpsBindingWithJsonP" 
        contract="KPIGetter_Library.IKpiGetter" /> 

      <host> 
       <baseAddresses> 
        <add baseAddress="http://hodbd05:8000/kpigetter" /> 
        <add baseAddress="https://hodbd05:8001/kpigetter" /> 
       </baseAddresses> 
      </host> 
     </service> 
    </services> 

    <behaviors> 
     <endpointBehaviors> 

      <behavior name="restfulBehaviour"> 
       <webHttp/> 
      </behavior> 
     </endpointBehaviors> 

     <serviceBehaviors> 
      <behavior> 
       <serviceDebug includeExceptionDetailInFaults="true" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 

    <protocolMapping> 
     <add binding="webHttpBinding" scheme="http" /> 
    </protocolMapping> 

    <bindings> 
     <webHttpBinding> 
       <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true"> 
        <security mode="None" /> 
       </binding> 

       <binding name="webHttpsBindingWithJsonP" crossDomainScriptAccessEnabled="true"> 
        <security mode="Transport" /> 
       </binding> 
     </webHttpBinding> 

    </bindings> 
</system.serviceModel> 

0

一個重要的問題是您應該使用webHttpBinding而不是啓用ajax的WCF服務的basicHttpBinding。

在這裏找到一個簡單的工作示例:Scott's blog on asp.net

相關問題