我正在开发一个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天才弄明白......所有的缓冲区都没有任何帮助
解决方案:
编辑:客户端方法
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
答案 0 :(得分:0)
我发现了这个问题, 它是关于绑定的命名,我忘了让端点使用绑定配置
<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>