简体   繁体   English

wcf服务错误请求400流

[英]wcf service bad request 400 streaming

I am developing a wcf service, to upload xml files to a storage database, for that reason i am ziping the file, saving it to a memorystream and passing it to the service with PushData(Stream as MemoryStream) Unfortunatly i cant get it to work. 我正在开发wcf服务,将xml文件上传到存储数据库,因此,我将文件压缩,保存到memorystream并通过PushData(Stream作为MemoryStream)传递给服务,不幸的是,我无法使它正常工作。 It seems i have some configuration missing, or wrong. 看来我有一些配置丢失或错误。 I host the service on an iis 8.0 as self hosted in storageservice.svc The Error Msg is: 400 bad request 我将服务托管在iis 8.0上,就像在storageservice.svc中自行托管一样。错误消息是:400错误的请求

here are my config files 这是我的配置文件

client side app config 客户端应用程序配置

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
          <binding name="BasicHttpBinding_IStorageService"     maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed"  receiveTimeout="00:10:00">
            <security mode="None"/>
          </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://10.5.1.6:8001/StorageService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IStorageService"
           name="BasicHttpBinding" contract="StorageService.IStorageService" />
    </client>
</system.serviceModel>
</configuration>

server side web config 服务器端Web配置

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <system.web>
    <compilation debug="true" />
    <httpRuntime maxRequestLength="2147483647"/>
    </system.web>
    <system.serviceModel>
    <services>
      <service name="Namespace.StorageService">
        <endpoint address="" binding="basicHttpBinding" contract="Namespace.IStorageService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://10.5.1.6:8001/" />
            <add baseAddress="net.tcp://10.5.1.6:10001/" />
          </baseAddresses>
        </host>
    </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>       
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
     <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed"  receiveTimeout="00:10:00" >
          <security mode="None"/>
        </binding>
      </basicHttpBinding>
    </bindings>
<protocolMapping>
      <add binding="basicHttpBinding" scheme="http"/>
    </protocolMapping>
  </system.serviceModel>
</configuration>

I really need help, tried 3 days to figure it out ... and all the buffersizes didnt help anything 我真的需要帮助,尝试了3天才能弄清楚...而且所有buffersizes都无济于事

Solutions Tried: 尝试过的解决方案:

  1. Add readerquotas element in binding 在绑定中添加readerquotas元素
  2. Use Mtom messageEncoding 使用Mtom messageEncoding
  3. Enable Tracing (unfortunatly didn't do anything) 启用跟踪(不幸的是什么也没做)

EDIT: Client Method 编辑:客户端方法

  Using client As New StorageService.StorageServiceClient
            client.Open()
            Dim helper As CirrostratusHelper = New CirrostratusHelper
            Dim data As CirrostratusStorage = helper.GenerateData()
            Dim gdata = data.GenerateData
            For Each item In gdata
                Try
                    Dim memorystream As New MemoryStream
                    Dim databasedaata As ZipArchive = item.Value.DatabaseData
                    databasedaata.Save(memorystream)
                    memorystream.Seek(0, SeekOrigin.Begin)
                  ' this method produces the bad exception '
                    client.PushData(memorystream)
                Catch ex As Exception                  
                    Dim test = ex.Message & ex.StackTrace
                End Try
            Next
            client.Close()
        End Using

Servive Method: 服务方式:

   Public Function PushData(DataStream As Stream) As Boolean Implements IStorageService.PushData
      Const buffersize As Integer = 2048
            Dim buffer(buffersize) As Byte
            Dim bytesread As Integer = bytesread = DataStream.Read(buffer, 0, buffersize)
            Dim DataMemoryStream As New MemoryStream
            While bytesread > 0
                bytesread = DataStream.Read(buffer, 0, buffersize)
                DataMemoryStream.Write(buffer, 0, buffersize)
            End While
            DataMemoryStream.Seek(0, SeekOrigin.Begin)
            Dim zip As ZipArchive = ZipArchive.Read(DataMemoryStream)
              '...'
    end function

I found the issue, it was about the naming for the binding and i forgot to make the endpoint use the bindingconfiguration 我发现了问题,这是关于绑定的命名的,我忘了让端点使用bindingconfiguration

<bindings>
  <basicHttpBinding>
    <binding name="basicHttpBinding_Storage" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed"  receiveTimeout="00:10:00" >
      <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxStringContentLength="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647"/>
      <security mode="None"/>
    </binding>
  </basicHttpBinding>
</bindings>
 <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding_Storage" contract="DynaMed.IStorageService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WCF IIS服务文件流式传输远程服务器返回意外响应:(400)错误的请求。 - WCF IIS service file streaming The remote server returned an unexpected response: (400) Bad Request. WCF Rest JSON服务400错误请求 - WCF Rest JSON service 400 bad request 大型 WCF Web 服务请求因 (400) HTTP 错误请求而失败 - Large WCF web service request failing with (400) HTTP Bad Request 与Jquery Mobile一起使用WCF服务返回400错误请求 - Consuming WCF service with Jquery Mobile is returning a 400 bad request 调用WCF服务操作时HTTP 400 Bad Request? - HTTP 400 Bad Request when calling WCF Service Operation? 400错误请求将xml有效负载发送到WCF REST服务 - 400 bad request sending xml payload to WCF REST service 错误 400(错误请求):我的 WCF 服务未考虑 maxReceivedMessageSize - Error 400 (bad request): maxReceivedMessageSize not taken into account for my WCF service 这是WCF配置导致我的400错误请求吗? - Is this WCF configuration causing my 400 bad request? 尝试将Web引用添加到WCF服务时出现HTTP 400 Bad Request错误 - HTTP 400 Bad Request error attempting to add web reference to WCF Service 从Win8应用程序到WCF服务的HttpClient.PostAsync给出错误400错误请求 - HttpClient.PostAsync to WCF service from Win8 app gives Error 400 Bad Request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM