2013-08-16 120 views
0

我在訪問wcf服務時遇到錯誤請求400的問題。我已嘗試所有與此主題相關的解決方案,但仍未解決。 WCF服務在IIS7上。頻繁訪問wcf休息服務時出現錯誤請求400錯誤

我想用下面的代碼調用服務。

try 
     { 
      WebClient client = new WebClient(); 
      byte[] data = client.DownloadData(ApplicationRunTimeSettings.ServiceURL() + userID); 
      Stream stream = new MemoryStream(data); 

      DataContractJsonSerializer obj = new DataContractJsonSerializer(typeof(string)); 
      result = obj.ReadObject(stream).ToString(); 
     } 
     catch (Exception) 
     { 

     } 


     return result; 

在服務配置文件是下面的配置文件是同爲WCF和Web應用程序。實際上,wcf服務是在Web應用程序和託管在iis7上的Web應用程序中開發的,我們正在使用它來訪問該服務。

配置文件如下。大多數情況下,它不會返回錯誤,但會在一段時間後崩潰。 wcf服務的請求頻繁。數據是JSON的形式。


現在做下面的後建議serviceThrottling web.config文件看起來像下面提到的變化,但它仍然給出了同樣的錯誤有時。

<system.web> 
<sessionState timeout="1440"/> 
<customErrors mode="Off"/> 
<httpRuntime executionTimeout="90" maxRequestLength="104857600" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100" enableVersionHeader="true"/> 
<!--set compilation defug="false" when releasing--> 
<compilation targetFramework="4.0" > 
    <assemblies> 
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
    <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
    <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
    <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
    </assemblies> 
</compilation> 
<authentication mode="Forms"> 
    <forms loginUrl="~/Account/LogOn" timeout="86400"/> 
</authentication> 
<pages> 
    <namespaces> 
    <add namespace="System.Web.Helpers"/> 
    <add namespace="System.Web.Mvc"/> 
    <add namespace="System.Web.Mvc.Ajax"/> 
    <add namespace="System.Web.Mvc.Html"/> 
    <add namespace="System.Web.Routing"/> 
    <add namespace="System.Web.WebPages"/> 
    </namespaces> 
</pages> 
</system.web> 
<system.webServer> 
<security> 
    <requestFiltering> 
    <!-- maxAllowedContentLength = bytes --> 
    <requestLimits maxAllowedContentLength="104857600"/> 
    </requestFiltering> 
</security> 
<validation validateIntegratedModeConfiguration="false"/> 
<modules runAllManagedModulesForAllRequests="true"/> 
</system.webServer> 
<runtime> 
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
    <dependentAssembly> 
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/> 
    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0"/> 
    </dependentAssembly> 
</assemblyBinding> 
</runtime> 
<system.serviceModel> 

<services> 
    <service name="Glance.DynamicBusinessService.DynamicBusinessService" behaviorConfiguration="ServiceBehaviour"> 
    <!-- Service Endpoints --> 
    <!-- Unless fully qualified, address is relative to base address supplied above --> 
    <endpoint address="customBinding" binding="customBinding" bindingConfiguration="basicConfig" contract="Glance.DynamicBusinessService.IDynamicBusinessService"/> 
    <endpoint address="" binding="webHttpBinding" contract="Glance.DynamicBusinessService.IDynamicBusinessService" behaviorConfiguration="REST"> 
     <!-- 
      Upon deployment, the following identity element should be removed or replaced to reflect the 
      identity under which the deployed service runs. If removed, WCF will infer an appropriate identity 
      automatically. 
     --> 
    </endpoint> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="throttleThis"> 
     <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
     <serviceMetadata httpGetEnabled="True" /> 
     <serviceThrottling 
      maxConcurrentCalls="40" 
      maxConcurrentInstances="20" 
      maxConcurrentSessions="20"/> 

     <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
    </behavior> 
    </serviceBehaviors> 
    <endpointBehaviors> 
    <behavior name="REST"> 
     <webHttp/> 
    </behavior> 
    </endpointBehaviors> 
</behaviors> 
<bindings> 

    <webHttpBinding> 
    <binding maxReceivedMessageSize="999999999" receiveTimeout="24" closeTimeout="24" maxBufferPoolSize="999999999" maxBufferSize="999999999"> 
     <readerQuotas maxDepth="32" maxStringContentLength="999999999" maxArrayLength="99999" maxBytesPerRead="4096" maxNameTableCharCount="99999" /> 
    </binding> 
    </webHttpBinding> 

    <customBinding> 
    <binding name="basicConfig"> 
     <binaryMessageEncoding/> 
     <httpTransport transferMode="Streamed" maxReceivedMessageSize="67108864"/> 
    </binding> 
    </customBinding> 
</bindings> 
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0"/> 
</system.serviceModel> 
</configuration> 

感謝您的任何建議和幫助。

回答

0

我會試圖在客戶端和主機上註釋掉配置行,然後嘗試運行它。該配置似乎設置了最低限度和性能限制。如果這不會改變任何內容,您可以嘗試設置性能限制。

您可以將其添加到配置中並修改設置,直到Web服務的性能平滑。例如,併發呼叫的默認值是16,但如果使用ServiceThrottling提高該數字,則可能會得到更好的結果。

<serviceBehaviors> 
     <behavior name="throttleThis"> 
      <serviceMetadata httpGetEnabled="True" /> 
      <serviceThrottling 
       maxConcurrentCalls="40" 
       maxConcurrentInstances="20" 
       maxConcurrentSessions="20"/> 
     </behavior> 
    </serviceBehaviors> 
+0

嗨,布賴恩感謝您的建議,但它仍然給出了不好的請求錯誤有時。我已經使用您的更改編輯了我的配置文件。你可以看看。 – Vijay

+0

這些類型的問題不容易調試。您可以嘗試使用Fiddler作爲代理來捕獲主機和客戶端之間來回傳遞的消息。另外,打開日誌記錄。 – Brian

相關問題