[英]WCF IIS service file streaming The remote server returned an unexpected response: (400) Bad Request.
[英]wcf service bad request 400 streaming
我正在開發wcf服務,將xml文件上傳到存儲數據庫,因此,我將文件壓縮,保存到memorystream並通過PushData(Stream作為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>
服務器端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>
我真的需要幫助,嘗試了3天才能弄清楚...而且所有buffersizes都無濟於事
嘗試過的解決方案:
編輯:客戶端方法
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
我發現了問題,這是關於綁定的命名的,我忘了讓端點使用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.