【发布时间】:2011-06-16 02:26:18
【问题描述】:
我感兴趣地阅读了以下帖子,因为它完全复制了我遇到的问题(并且让我发疯) “对于将 UploadFile 操作中的请求作为流,该操作必须有一个类型为 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
我想要实现的只是使用标准文件名/流参数从 android 设备发布图像(jpeg/png)。很可能这是我配置错误、误解或遗漏的简单事情,但我需要有一个概念证明的解决方案。
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 设置 -->
<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 查询
提前致谢 紧缩
【问题讨论】:
-
对于将UploadFile 操作中的请求作为流,该操作必须有一个类型为Stream 的参数。浏览元数据端点时发生错误。
-
(5 年后..)这个要了我的命。我有两个 WCF 服务项目,都是 .Net 4.5.1。一方面,以 Stream 作为 3 个参数中的 1 个的服务可以完美运行,另一方面,它会引发此异常。我对这两个 web.config 进行了文件比较,它们是相同的......但我无法解决这个问题。即使重新创建“有故障的”服务也无法修复它。我很困惑。