[英]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: 尝试过的解决方案:
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.