gpt4 book ai didi

c# - Web 服务仅针对某些请求返回 "Access is denied"

转载 作者:太空宇宙 更新时间:2023-11-03 17:34:03 24 4
gpt4 key购买 nike

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

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

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

我很确定问题出在服务和应用程序之间,甚至出在应用程序的配置中。

任何人都可以帮助我发现为什么我会收到这个模糊的“访问被拒绝”错误吗?让我知道是否需要我提供更多信息。

编辑:我控制网络服务。

我已经尝试通过一个小的 Windows 窗体应用程序调用该服务,但我从未见过任何错误。

我是通过某种契约(Contract)客户端调用网络服务吗?我不确定具体细节,但我只有一个指向该服务的服务引用,然后我可以声明一个客户端,然后使用其中的方法。

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

至于其他问题,我还不确定。我会进一步调查。

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

我在这里和那里省略了一些我认为可能过于暴露的内容。

最佳答案

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

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

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

关于c# - Web 服务仅针对某些请求返回 "Access is denied",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8016170/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com