我正在尝试使用带有消息合同的WCF流,因为我需要在流本身旁边添加其他参数.
基本上我正在创建一个文件上传和下载服务,顶部还有一些额外的逻辑.
不幸的是,当我尝试从浏览器点击服务以检查一切正常时,我收到以下错误:
'/'应用程序中的服务器错误.合同'IFileTransferService'中的"UploadFile"操作使用具有SOAP头的MessageContract.None MessageVersion不支持SOAP标头.
不幸的是谷歌搜索它并没有产生任何帮助我的重要结果.你们能帮助我吗?这里是服务的细节(我已经删除了下载部分,因为空间的原因).
[ServiceContract(Namespace = "http://www.acme.org/2009/04")]
public interface IFileTransferService
{
[OperationContract(Action = "UploadFile")]
void UploadFile(FileUploadMessage request);
}
[MessageContract]
public class FileUploadMessage
{
[MessageHeader(MustUnderstand = true)]
public FileMetaData Metadata { get; set; }
[MessageBodyMember(Order = 1)]
public Stream FileByteStream { get; set; }
}
[DataContract(Namespace = "http://schemas.acme.org/2009/04")]
public class FileMetaData
{
[DataMember(Name="FileType", Order=0, IsRequired=true)]
public FileTypeEnum fileType;
[DataMember(Name="localFilename", Order=1, IsRequired=false)]
public string localFileName;
[DataMember(Name = "remoteFilename", Order = 2, IsRequired = false)]
public string remoteFileName;
}
Run Code Online (Sandbox Code Playgroud)
我试图使用basichttpbinding和customhttp绑定,但效果不佳:
<customBinding> …Run Code Online (Sandbox Code Playgroud) 我感兴趣地阅读了以下帖子,因为它是我遇到的问题的完全复制品(并且让我疯狂)"对于操作中的请求,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 -接收-任意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
}
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
使用vs2010和IIS …
1 namespace Uploader
2 {
3 using System;
4 using System.IO;
5 using System.ServiceModel;
6 using System.ServiceModel.Description;
7 using System.ServiceModel.Web;
8 using System.Drawing;
9 using System.Drawing.Imaging;
10 using System.Net;
11 using System.Xml;
12
13 [ServiceContract(Namespace = "http://Uploader")]
14 public interface IUploaderService
15 {
16 [OperationContract, WebInvoke(Method = "POST",UriTemplate = "File/{fileName}")]
17 bool UploadFile(string fileName, Stream fileContents);
18 }
19
20 [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
21 public class UploaderService : IUploaderService
22 {
23 public bool UploadFile(string fileName, Stream fileContents)
24 { …Run Code Online (Sandbox Code Playgroud)