我正在开发一个 wcf 服务,将 xml 文件上传到存储数据库,因此我正在压缩文件,将其保存到内存流并使用 PushData(Stream as MemoryStream) 将其传递给服务不幸的是我无法让它工作. 看来我有一些配置丢失或错误。我将服务托管在 iis 8.0 上作为自托管在 storageservice.svc 错误消息是:400 错误请求
这是我的配置文件
客户端应用配置
<?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>
服务器端网络配置
<?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>
我真的需要帮助,尝试了 3 天才弄明白......所有的缓冲区大小都没有帮助
尝试过的解决方案:
- 在绑定中添加 readerquotas 元素
- 使用 Mtom 消息编码
- 启用跟踪(不幸的是没有做任何事情)
编辑:客户端方法
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
服务方式:
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