WCF 调用收到“访问被拒绝”通过 .NET 4 上的 HTTPS

发布于 2024-10-03 11:35:07 字数 3949 浏览 5 评论 0原文

以前从未遇到过问题,但升级到 .NET 4 后,我在尝试通过 HTTPS 调用 WCF 方法时收到“访问被拒绝”的消息。如果我使用 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 下。

Never had problems before but after upgrading to .NET 4, I am getting "Access is Denied" when trying to invoke a WCF method over HTTPS. If I use HTTP instead of HTTPS, everything works fine. Any possible solutions for this? I can provide more specific information if requested.

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>

Note: Works PERFECTLY fine over HTTP. Problem ONLY exists under HTTPS.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往日情怀 2024-10-10 11:35:07

在您的设置中,您没有定义安全性 - 因此您只能使用 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>

仅定义绑定配置而不具有实际引用它的端点并没有真正的帮助......

With your setup, you have no security defined -- thus you can only connect using 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>

If you want to use https, you need to enable transport security:

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

Update: Now that you have defined your secure HTTPS binding configuration:

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

you also need to configure an endpoint to use that binding configuration, of course!

<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>

Just defining the binding configuration without having an endpoint that actually refers to it doesn't really help......

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文