使这些工作在一起:IDataServiceStreamProvider,ServiceBase,DataServiceHost&分块HTTP传输编码 [英] Making these work together: IDataServiceStreamProvider, ServiceBase, DataServiceHost & chunked HTTP Transfer-Encoding

查看:64
本文介绍了使这些工作在一起:IDataServiceStreamProvider,ServiceBase,DataServiceHost&分块HTTP传输编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个自定义数据服务提供程序,到目前为止一切正常。

I've created a custom Data Service Provider, where everything was working fine up to now.

一旦我开始调试使用SetSaveStream上传文件,它一切都工作了小文件,直到我超过64k,这给了我一个400 Bad Request。

Once I started debugging the uploading of files using SetSaveStream it all worked with small files, until I went over 64k, which gave me a 400 Bad Request.

经过多次环顾四周我偶然发现了这个:

After much looking around I stumbled upon this:

http://msdn.microsoft.com/en-us/library/ee960144(VS.100 ).aspx  " 默认情况下,客户端发送大型二进制流
by使用分块HTTP传输编码。由于ASP.NET Development Server不支持这种编码,因此您无法使用此Web服务器来托管必须接受大型二进制流的流数据服务。"

http://msdn.microsoft.com/en-us/library/ee960144(VS.100).aspx "By default, the client sends large binary streams by using a chunked HTTP Transfer-Encoding. Because the ASP.NET Development Server does not support this kind of encoding, you cannot use this Web server to host a streaming data service that must accept large binary streams."

我一直在试图强制将dataservicehost的TransferMode绑定到Streaming而不是Buffered,但是不起作用。

我是自我在Windows服务中托管服务并开始非常简单:

 

    public void StartService()
    {
      var configuration = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
      
      var debugMode = Convert.ToBoolean(configuration.AppSettings.Settings["Debug"].Value);
      var baseUrl = new Uri(configuration.AppSettings.Settings["BaseUrl"].Value);
      var rootPath = configuration.AppSettings.Settings["RootPath"].Value;

      Uri[] uriArray = { baseUrl };
      Type serviceType = typeof(DocumentService);

      FileSystemTracker.Instance.RootPath = rootPath;
      FileSystemTracker.Instance.TrackFileSystem();

      _documentService = new DataServiceHost(serviceType, uriArray);
      _documentService.Open();
    }

 

StreamProvider只返回指向测试文件的FileStream。客户将其设为:

 

      Stream newFile = new FileStream(@"C:\Temp\tstfile.txt", FileMode.Open);

      documentService.SetSaveStream(docToUpdate, newFile, true, "text/plain", string.Empty);
      documentService.SaveChanges();

如何使我的自托管WCF数据服务接受大于64k的流,这些流使用Transfer-Encoding:chunked in the背景?

How do I make my self-hosted WCF Data Service accept streams bigger than 64k, which use Transfer-Encoding: chunked in the background?

 




推荐答案

这当我尝试使用更大的文件时会发生什么,第一个HTTP标头是:

This is what happens when I try with a bigger file, first HTTP header is:

 

PUT http://192.168.123.10:20000/Documents(guid'259bd1f9-2c18-4643-ab47-0dfa27a418fc')/


值HTTP / 1.1
用户代理:Microsoft ADO.NET数据服务
DataServiceVersion:1.0; NetFx
MaxDataServiceVersion:2.0; NetFx
接受:application / atom + xml,application / xml
Accept-Charset:UTF-8
Content-类型:特克斯t / plain
Slug:
主机:192.168.123.10:20000
转账编码:chunked
预期:100-continue

10000
------------------------------------------------- -------------------------------
Hello world! (这里有很多数据)
value HTTP/1.1 User-Agent: Microsoft ADO.NET Data Services DataServiceVersion: 1.0;NetFx MaxDataServiceVersion: 2.0;NetFx Accept: application/atom+xml,application/xml Accept-Charset: UTF-8 Content-Type: text/plain Slug: Host: 192.168.123.10:20000 Transfer-Encoding: chunked Expect: 100-continue 10000 -------------------------------------------------------------------------------- Hello world! (a lot of data here)

 

这会返回400个错误请求,之后客户端继续发送垃圾邮件:

This returns 400 bad request, after which the client keeps on spamming this:

 

PUT http://192.168.123.10:20000/Documents(guid'259bd1f9-2c18-4643-ab47-0dfa27a418fc')/


值HTTP / 1.1
用户代理:Microsoft ADO.NET数据服务
DataServiceVersion:1.0; NetFx
MaxDataServiceVersion:2.0; NetFx
接受:application / atom + xml,application / xml
Accept-Charset:UTF-8
Content-Type:text / plain
Slug:
主持人: 192.168.123.10:20000
内容长度:78589
预期:100-continue

------------------- -------------------------------------------------- -----------
Hello world(整个文件)
value HTTP/1.1 User-Agent: Microsoft ADO.NET Data Services DataServiceVersion: 1.0;NetFx MaxDataServiceVersion: 2.0;NetFx Accept: application/atom+xml,application/xml Accept-Charset: UTF-8 Content-Type: text/plain Slug: Host: 192.168.123.10:20000 Content-Length: 78589 Expect: 100-continue -------------------------------------------------------------------------------- Hello world (the entire file)

 

  ;

所有这些都得到400个错误请求

Which all get a 400 bad request as well

在调试模式下,我的代码永远不会引发异常,所以我不知道在哪里插入

In debug mode, my code never raises an exception, so I have no idea where to plug in


这篇关于使这些工作在一起:IDataServiceStreamProvider,ServiceBase,DataServiceHost&分块HTTP传输编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆