Вызов WCF получает «Доступ запрещен» через HTTPS в .NET 4 - PullRequest
2 голосов
/ 23 ноября 2010

Никогда раньше проблем не было, но после обновления до .NET 4 я получаю сообщение «Отказано в доступе» при попытке вызвать метод WCF через HTTPS.Если я использую HTTP вместо HTTPS, все работает нормально.Любые возможные решения для этого?Я могу предоставить более конкретную информацию, если требуется.

web.config

    <system.serviceModel>
            <behaviors>
              <serviceBehaviors>
                <behavior name="some_product.SomeServiceAspNetAjaxBehavior">
                  <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
              </serviceBehaviors>
              <endpointBehaviors>
                <behavior name="some_product.SomeServiceAspNetAjaxBehavior">
                  <enableWebScript />
                </behavior>
              </endpointBehaviors>
            </behaviors>
            <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
            <services>
              <service name="some_product.SomeService">
                <endpoint address="" behaviorConfiguration="some_product.SomeServiceAspNetAjaxBehavior" bindingConfiguration="BasicHttpBinding_SomeService" binding="webHttpBinding" contract="some_product.SomeService"/>
              </service>
            </services>
            <bindings>
              <basicHttpBinding>        
<binding name="BasicHttpsBinding_SomeService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
       <readerQuotas maxDepth="32" maxStringContentLength="8192" 
                     maxArrayLength="16384" maxBytesPerRead="4096" 
                     maxNameTableCharCount="16384"/>
       <security mode="Transport">
          <transport clientCredentialType="Windows" 
                     proxyCredentialType="None" realm=""/>
        </security>
     </binding>
                <binding name="BasicHttpBinding_SomeService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
                  <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
                  <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
                    <message clientCredentialType="UserName" algorithmSuite="Default"/>
                  </security>
                </binding>
              </basicHttpBinding>
              <webHttpBinding>
                <binding name="BasicHttpBinding_SomeService" maxReceivedMessageSize="300000" allowCookies="true"  >
                  <readerQuotas maxStringContentLength="300000" />
                </binding>
              </webHttpBinding>
            </bindings>
            <client>
              <endpoint address="/someurl/SomeService.svc" binding="webHttpBinding" bindingConfiguration="BasicHttpBinding_SomeService" contract="some_product.SomeService" name="BasicHttpBinding_SomeService"/>
<endpoint address="/someurl/SomeService.svc" binding="webHttpBinding" bindingConfiguration="BasicHttpsBinding_SomeService" contract="some_product.SomeService" name="BasicHttpsBinding_SomeService"/>
            </client>
          </system.serviceModel>

Примечание: прекрасно работает отлично по HTTP.Проблема существует ТОЛЬКО под HTTPS.

1 Ответ

1 голос
/ 23 ноября 2010

С вашей настройкой у вас нет определенной безопасности - таким образом, вы можете подключиться только по http:

<basicHttpBinding>        
    <binding name="BasicHttpBinding_SomeService" .....>
       <readerQuotas maxDepth="32" maxStringContentLength="8192" 
                     maxArrayLength="16384" maxBytesPerRead="4096" 
                     maxNameTableCharCount="16384"/>
       <security mode="None">
          <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
          <message clientCredentialType="UserName" algorithmSuite="Default"/>
        </security>
     </binding>
 </basicHttpBinding>

Если вы хотите использовать https, вам нужно включить безопасность транспорта:

<basicHttpBinding>        
    <binding name="BasicHttpBinding_Secure" .....>
       <readerQuotas ..../>
       <security mode="Transport">
          <transport clientCredentialType="Windows" 
                     proxyCredentialType="None" realm=""/>
        </security>
     </binding>
 </basicHttpBinding>

Обновление: Теперь, когда вы определили свою конфигурацию безопасной привязки HTTPS:

<bindings>
   <basicHttpBinding>
        <binding name="BasicHttpsBinding_SomeService" ......>
            <readerQuotas ......../>
            <security mode="Transport">
                <transport clientCredentialType="Windows" 
                           proxyCredentialType="None" realm=""/>
            </security>

вам также необходимо настроить конечную точку, чтобы использовать эту конфигурацию привязки, конечно же!

<services>
   <service name="some_product.SomeService">
      <endpoint 
           address="" 
           behaviorConfiguration="some_product.SomeServiceAspNetAjaxBehavior" 
           binding="webHttpBinding" 
           bindingConfiguration="BasicHttpBinding_SomeService" 
           contract="some_product.SomeService"/>

      <!-- add this endpoint !! -->       
      <endpoint 
           address="secure" 
           binding="basicHttpBinding" 
           bindingConfiguration="BasicHttpsBinding_SomeService" 
           contract="some_product.SomeService"/>
    </service>
 </services>

Простое определение конфигурации привязки без конечной точки, которая на самом деле ссылается на нее, на самом деле не помогает ......

...