2011-05-26 87 views
5

我有WCF服務,通過它我在數據庫中添加數據。它工作正常,但是當我嘗試發送大字節[]時,它返回「遠程服務器返回錯誤:NotFound」。發送大字節數組時出錯

的web.config

<?xml version="1.0"?> 
<configuration> 
    <connectionStrings> 
    <add name="JabsBaseConnectionString" connectionString="Data Source=TAHASAGHIR-PC\SQLEXPRESS;Initial Catalog=JabsBase;Integrated Security=True" providerName="System.Data.SqlClient"/> 
    </connectionStrings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0"> 
     <assemblies> 
     <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> 
     </assemblies> 
    </compilation> 
    <httpRuntime maxRequestLength="2097151" useFullyQualifiedRedirectUrl="true"/> 
    </system.web> 
    <system.serviceModel>  
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" /> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="SendLargeChat" 
       allowCookies="false" 
       bypassProxyOnLocal="false" 
       maxBufferPoolSize="2147483647" 
       maxReceivedMessageSize="2147483647" 
       maxBufferSize="2147483647" 
       closeTimeout="10:00:00" 
       openTimeout="10:00:00" 
       receiveTimeout="10:00:00" 
       sendTimeout="10:00:00" 
       transferMode="Streamed"> 
      <readerQuotas 
      maxArrayLength="2147483647" 
      maxBytesPerRead="2147483647" 
      maxDepth="2147483647" 
      maxNameTableCharCount="2147483647" 
      maxStringContentLength="2147483647" /> 
     </binding> 
     </basicHttpBinding>  
    </bindings> 
    <services> 
     <service name="Prototype.SendChatService" behaviorConfiguration="Prototype.SendChatServiceBehavior"> 
     <endpoint address="" binding="basicHttpBinding" bindingConfiguration="SendLargeChat" contract="Prototype.SendChatService" /> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     </service>  
    </services>  
    <behaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     <behavior name="Prototype.SendChatServiceBehavior"> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 

ServiceReferences.ClientConfig

<configuration> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding>   
     <binding name="BasicHttpBinding_ISendChatService" maxBufferSize="2147483647" 
      maxReceivedMessageSize="2147483647"> 
      <security mode="None" /> 
     </binding> 
     </basicHttpBinding>  
    </bindings> 
    <client>  
     <endpoint address="http://localhost:53756/PrototypeSite/SendChatService.svc" 
     binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISendChatService" 
     contract="SendChatService.ISendChatService" name="BasicHttpBinding_ISendChatService" /> 
    </client> 
    </system.serviceModel> 
</configuration> 

請求 POST http://localhost:53756/PrototypeSite/SendChatService.svc HTTP/1.1 主機:本地主機:53756 連接:保持活躍 的Referer:http://localhost:53756/PrototypeSite/ClientBin/Prototype.xap 內容長度:1348176 soapaction:「http://tempuri.org/ISendChatService/addMsg」 content-type:text/xml;字符集= UTF-8 接受:/ 的User-Agent:Mozilla的/ 5.0(Windows NT的6.1)爲AppleWebKit/534.24(KHTML,例如Gecko)鉻/ 11.0.696.68 Safari瀏覽器/ 534.24 接受編碼:gzip,放氣, SDCH 接受語言:EN-US,EN; q = 0.8 接收字符集:ISO-8859-1,utf-8; q = 0.7,*; q = 0.3

響應 HTTP/1.1 400 Bad Request 服務器:ASP.NET Development Server/10.0.0.0 日期:2011年5月26日星期四17:48:00 GMT X-AspNet-Version:4.0.30319 Cache-Control:private 內容長度:0 連接:關閉

回答

0

抱歉,我的回答是錯誤的! IGNORE IT

我會在幾個小時內刪除它,只是讓有評論的人看到它。

不要在SOAP 發送字節數組。

每個字節將被轉移爲<byte>128</byte>或類似的,這意味着它將平均需要10倍以上。

使用base64字符串代替 - 因此將您的屬性定義爲字符串並將其填充爲base64字符串。

+0

Aliostad,感謝您的快速響應!你可以請給出過程的細節,如何將字節數組轉換爲base64字符串,反之亦然? – Taha 2011-05-26 11:40:47

+0

哇。這真的是有用的知道。你有沒有解釋這個的參考? – Xhalent 2011-05-26 11:41:19

+0

這聽起來不太正確......我確信byte []被串行器編碼爲Base64字符串。 http://webservices20.blogspot.com/2010/10/important-wcf-performance-issue.html – TheNextman 2011-05-26 11:52:17

1

我想你應該採用同樣的

<readerQuotas ... 

在客戶端。

2

404/Not Found是Silverlight報告所有服務器錯誤的錯誤。如果您想知道從服務器返回的實際錯誤,您可以使用類似Fiddler的東西來查看正在發送和接收的內容,包括包含服務器返回的實際錯誤代碼和錯誤消息的標頭。

+0

這是很好的建議 – TheNextman 2011-05-26 13:15:31

+0

謝謝大衛......我正在編輯我原來的帖子!請檢查請求和響應。 – Taha 2011-05-26 17:59:47

+1

錯誤的請求可能是一些事情:發送的XML已損壞(您可以在Fiddler中檢查請求數據是否可以被視爲XML),請求使用的合同與服務器不同(不太可能如果你使用同一個WCF代碼編寫),或者請求違反範圍檢查。請求是否超過64KB?它可能會破壞WCF服務中設置的默認MaxReceivedMessageSize限制。 – David 2011-05-27 13:03:40

1

嘗試將executionTimeout設置添加到您的httpRuntime設置

<httpRuntime executionTimeout="110" maxRequestLength="..." /> 
1

以我的經驗,我收到了一個錯誤,因爲即使服務器上的服務被配置爲接收大量的數據,在HTTP運行時不是。確保你的httpRuntime有一個合適的maxRequestLength。

1

您還可以打開WCF日誌記錄以獲取更多信息。將以下內容添加到您的web.config中:

<system.diagnostics> 
    <sources> 
     <source name="System.ServiceModel" 
        switchValue="Information, ActivityTracing" 
        propagateActivity="true"> 
      <listeners> 
       <add name="traceListener" 
        type="System.Diagnostics.XmlWriterTraceListener" 
        initializeData= "c:\log\Traces.svclog" /> 
      </listeners> 
     </source> 
    </sources> 
</system.diagnostics>