2011-05-26 95 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>