WCF服务时Request.InputStream.Length为什么等于0,与webserver不一样
方法都是一样的,我客户端通过WebServer调用服务方法时,取HttpContext.Current.Request.InputStream.Length大于0,能取到值,但客户端通过调用wcf服务方法,在服务层取HttpContext.Current.Request.InputStream.Length等于0
wcf,
wcf也引用了System.ServiceModel.Activation,在类前面也加了
服务前加上个标识:[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
web.config中加入aspNetCompatibilityEnabled="true"
还是httpContext.Current.Request.InputStream.Length还是为0 --------------------编程问答-------------------- 怎么没有人回呢 --------------------编程问答-------------------- 1. 猜测和 WCF ServiceHost 有关。虽然开启兼容模式,但Request内容并没有完全赋值(或者已经被清空了)
2. 通过 OperationContext.Current.RequestContext.RequestMessage.ToString() 可以获得提交Request的Body
3. 开启兼容模式后 HttpContext.Current.Request.ContentLength 是正确的 --------------------编程问答-------------------- 主要是HttpContext.Current.Request.InputStream.Length这个值与webserver不一样,是什么回事 --------------------编程问答-------------------- 感谢fangxinggood,根据你的思想再修改一下代码即可,过几天再结账 --------------------编程问答--------------------
大侠和楼主是怎么解决的,我现在也遇到这样的问题,wcf服务类我加了兼容模式设置:
[AspNetCompatibilityRequirement(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
而且hosting项目app.config也已经设置aspNetCompatibilityEnabled="true"
但是在wcf服务层获取HttpContext.Current一直是null,求大神指引啊,急 --------------------编程问答-------------------- 除
补充:.NET技术 , Web Services