带有流的 WCF Rest Webservice [英] WCF Rest Webservice with stream
问题描述
我很感兴趣地阅读了以下帖子,因为它是我遇到的问题的精确复制品(让我发疯)要使操作 UploadFile 中的请求成为流,该操作必须具有一个类型为 Stream 的参数."-http://social.msdn.microsoft.com/Forums/en/wcf/thread/80cd26eb-b7a6-4db6-9e6e-ba65b3095267
I read the following post with interest as it is an exact replica of the problem I am experiencing (and driving me insane) "For request in operation UploadFile to be a stream the operation must have a single parameter whose type is Stream." -http://social.msdn.microsoft.com/Forums/en/wcf/thread/80cd26eb-b7a6-4db6-9e6e-ba65b3095267
我几乎遵循了我发现的所有代码/示例,但仍然无法解决此错误 -http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-receiving-arbitrary-data.aspx
I have pretty much followed all code/examples I have found and yet still cannot get around this error - http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-receiving-arbitrary-data.aspx
我想要实现的只是使用标准文件名/流参数从 android 设备发布图像(jpeg/png).这很可能是我配置错误、误解或遗漏的简单问题,但我需要有一个概念证明的解决方案.
All I would like to achieve is to post an image(jpeg/png) from an android device using the standard filename/stream parameters.More than likely it is something simple that I have misconfigured, misunderstood or left out but I need to have a solution for proof of concept.
public interface IConXServer
{
[OperationContract]
[WebInvoke(UriTemplate = "UploadImage({fileName})", Method="POST")]
void UploadImage(string fileName, Stream imageStream);
}
public class ConXWCFServer : IConXServer
{
public void UploadImage(string fileName, Stream imageStream)
{
//implement image save
}
}
web.config 设置-->
web.config settings -->
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="webHttpEndpoint" helpEnabled="false"/>
</webHttpEndpoint>
</standardEndpoints>
<bindings>
<webHttpBinding>
<binding name="webHttpBinding" transferMode="Streamed"/>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling maxConcurrentCalls="2147483647" maxConcurrentSessions="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
使用 vs2010 和 IIS Express.如果我注释掉上述方法,所有其他方法都可以工作并返回数据以及 wsdl 查询
Using vs2010 and IIS Express. If I comment out the above method all the others methods work and return data as well as the wsdl query
提前致以问候和感谢克恩
Regards and thanks in advance Kern
推荐答案
您提到了 WSDL,这让我相信您在尝试浏览服务的元数据端点时遇到了错误.因此,首先,WSDL 和 REST 不会一起使用,因此您根本不应该期望将它用于 REST 接口.忘记服务元数据概念甚至存在于 REST 世界中.
You mention WSDL, which leads me to believe you're getting the error while trying to browse the metadata endpoint for the service. So, first off, WSDL and REST don't go together, so you shouldn't expect to use it at all for a REST interface. Forget the service metadata concept even exists in the REST world.
Next 虽然 REST 的 webHttpBinding 确实支持 Stream body 参数前面的参数,但其他绑定不支持,并且必须有单个 Stream 参数或带有标头和流主体的消息协定.
Next While it's true the REST's webHttpBinding supports parameters in front of the Stream body parameter, other bindings do not and there must either be a single Stream parameter or a message contract with headers and a stream body.
所以,最后,问题根本不在于 REST webHttpBinding,我敢打赌它工作得很好.如果不是这样,我绝对会感到震惊,因为您没有做任何不应该在该部门工作的事情.问题是您希望元数据端点为您定义的服务合同生成 WSDL,而这不受支持.
So, in the end, the problem is not with the REST webHttpBinding at all, I bet it works just fine. If it doesn't I would be absolutely shocked because you're not doing anything that shouldn't work in that department. The problem is that you're expecting the metadata endpoint to generate WSDL for the service contract you've defined and that's just not supported.
这篇关于带有流的 WCF Rest Webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!