Web服务仅针对某些请求返回“拒绝访问”

时间:2011-11-04 21:54:52

标签: c# asp.net web-services

我在C#Web应用程序中有一个ASP.NET,它使用来自Web服务的数据。它在大多数情况下工作得很好,但有时候,通常在请求更大的数据集时,它只返回一个拒绝访问错误。

例如,如果我调用该服务从特定日期范围之间返回一些文档,并且范围足够小,则可以正常工作。但是,如果我将范围扩展得太远,则会返回此错误。这让我相信这是一个大小或时间问题。

但是,如果我尝试返回所有文档,它几乎立即返回Access被拒绝错误,没有等待。

我非常确定服务和应用程序之间存在问题,甚至是应用程序的配置。

任何人都可以帮助我发现为什么我得到这个模糊的Access被拒绝错误?如果我应该提供更多信息,请告诉我。

修改 我控制着Web服务。

我尝试通过一个小窗口应用程序调用该服务,我从未见过任何错误。

我是通过某种合同客户呼叫网络服务的吗?我不确定具体细节,但我只是有一个指向服务的服务引用,然后我能够声明一个客户端,然后使用其中的方法。

我可以在浏览器中正常访问该服务。

就其他问题而言,我还不确定。我会进一步研究它。

编辑2: 这是客户端的配置:

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    //omitted
  </connectionStrings>
  <system.web>
    <httpRuntime executionTimeout="300" maxRequestLength="51200" />
<pages theme="Theme1" />
<compilation debug="true" targetFramework="4.0">
  <assemblies>
    //omitted 
  </assemblies>
</compilation>
<authentication mode="Windows" />
<authorization>
  <deny users="?" />
</authorization>
<membership>
  <providers>
    <clear />
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
  </providers>
</membership>
<profile>
  <providers>
    <clear />
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
  </providers>
</profile>
<roleManager enabled="false">
  <providers>
    <clear />
    <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
    <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
  </providers>
</roleManager>
<httpHandlers>
    <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
</httpHandlers>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
  <add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" />
</handlers>
</system.webServer>
<appSettings>
//omitted
</appSettings>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="DefaultEndpoint" closeTimeout="00:09:00" openTimeout="00:09:00" receiveTimeout="00:10:00" sendTimeout="00:09:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
    <binding name="DefaultEndpoint1" closeTimeout="00:09:00" openTimeout="00:09:00" receiveTimeout="00:10:00" sendTimeout="00:09:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="/*omitted*/ " binding="basicHttpBinding" behaviorConfiguration="ServiceBehavior" bindingConfiguration="DefaultEndpoint" contract="/*omitted*/ " name="DefaultEndpoint" />
  <endpoint address="/*omitted*/ " binding="basicHttpBinding" behaviorConfiguration="ServiceBehavior" bindingConfiguration="DefaultEndpoint1" contract="/*omitted*/ " name="DefaultEndpoint1" />
</client>
<behaviors>
  <endpointBehaviors>
    <behavior name="ServiceBehavior">
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
  </endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

这是服务的配置:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=/*omitted*/" >
        <section name="ITSLogger.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=/*omitted*/" requirePermission="false" />
    </sectionGroup>
</configSections>
<system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Windows"></authentication>
    <!--<anonymousIdentification enabled="false"/>-->
</system.web>
<system.serviceModel>
<services>
  <service behaviorConfiguration="RWS.ServiceImplementation.ResearchService_Behavior"
    name="RWS.ServiceImplementation.ResearchService">
    <endpoint address="" binding="basicHttpBinding" name="DefaultEndpoint"
      bindingNamespace="http://researchwebservice.model/research" bindingConfiguration="userHttp"
      contract="RWS.ServiceContracts.IResearchServiceContract"/>
    <!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />-->
  </service>
</services>
<bindings>
  <basicHttpBinding>
    <binding name="userHttp"
             closeTimeout="00:01:00"
             openTimeout="00:01:00"
             receiveTimeout="00:10:00"
             sendTimeout="00:01:00"
             allowCookies="false"
             bypassProxyOnLocal="false"
             hostNameComparisonMode="StrongWildcard"
             maxBufferSize="2147483647"
             maxBufferPoolSize="2147483647"
             maxReceivedMessageSize="2147483647"
             messageEncoding="Text"
             textEncoding="utf-8"
             transferMode="Buffered"
             useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647"
                    maxStringContentLength="2147483647"
                    maxArrayLength="2147483647"
                    maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647" />
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Ntlm" />
        <message clientCredentialType="UserName"/>
      </security>
    </binding>

  </basicHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
    <behavior name="RWS.ServiceImplementation.ResearchService_Behavior">
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceMetadata httpGetEnabled="true" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<connectionStrings>
  <add name="ITSLogger.Properties.Settings.ITSLoggerConnectionString"
        connectionString=/*omitted*/
        providerName="System.Data.SqlClient" />
</connectionStrings>

<applicationSettings>
  <ITSLogger.Properties.Settings>
    <setting name="LogFilePath" serializeAs="String">
      <value>C:\ITSLogger\LoggerTest\</value>
    </setting>
    <setting name="MailServer" serializeAs="String">
    <value>/*omitted*/</value>
  </setting>
  <setting name="MailRecipient" serializeAs="String">
    <value>sklingbeil@itsmtc.com</value>
  </setting>
  <setting name="CanLogToEmail" serializeAs="String">
    <value>False</value>
  </setting>
  <setting name="CanLogToFlatFile" serializeAs="String">
    <value>False</value>
  </setting>
  <setting name="CanLogToTrace" serializeAs="String">
    <value>False</value>
  </setting>
  <setting name="CanLogToConsole" serializeAs="String">
    <value>False</value>
  </setting>
  <setting name="CanLogToEventLog" serializeAs="String">
    <value>true</value>
  </setting>
  <setting name="CanLogToDB" serializeAs="String">
    <value>False</value>
  </setting>
</ITSLogger.Properties.Settings>
</applicationSettings>

<system.diagnostics>
<sources>
  <source name="System.ServiceModel"
                switchValue="Information, ActivityTracing"
                propagateActivity="true">
    <listeners>
      <add name="traceListener"
          type="System.Diagnostics.XmlWriterTraceListener"
          initializeData= "/*omitted*/" />
    </listeners>
  </source>
</sources>
</system.diagnostics>

</configuration>

我在这里和那里省略了一些我认为可能太暴露的东西。

3 个答案:

答案 0 :(得分:6)

如果您可以从服务和客户端配置文件发布配置部分,将会很有帮助。

请参阅绑定的maxReceivedMessageSize / MaxBufferSize / MaxBufferPoolSize属性并尝试增加值。 http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpbinding.aspx

如果可能,请打开WCF跟踪并验证请求和响应消息。

答案 1 :(得分:5)

如果您有权访问Web服务以获取调试信息,则应该查看您请求的输出数据的二进制大小。默认情况下,可以通过Web服务传输有限的限制(4096k)。您可以通过更改web.config文件中的以下属性来覆盖此设置:

<configuration>
    <system.web>
        <httpRuntime maxRequestLength="16256" />
    </system.web>
</configuration> 

对于Web服务,我在访问被拒绝错误中看到了这个结果。我从来没有得到过令人满意的回答,说明为什么会这样,而不是例外。

答案 2 :(得分:0)

如果要解析服务器上的数据类型 - 检索文档 - 。服务器上的数据类型之间的转换通常会导致Web服务死亡,主要原因是溢出。