问题描述
|
我正在尝试将MessageContract添加到我的WCF服务中,类似于此问题中发生的事情:WCF:将流与Message Contracts一起使用
这是我得到的例外:
无法加载操作'UploadFile \',因为它的参数或返回类型为System.ServiceModel.Channels.Message或具有MessageContractAttribute和其他不同类型参数的类型。当使用System.ServiceModel.Channels.Message或具有MessageContractAttribute的类型时,该方法不得使用任何其他类型的参数。
这是我的合同:
[ServiceContract]
public interface IFile
{
[OperationContract]
bool UploadFile(FileUpload upload);
}
[MessageContract]
public class FileUpload
{
[MessageHeader(MustUnderstand = true)]
public int Username { get; set; }
[MessageHeader(MustUnderstand = true)]
public string Filename { get; set; }
[MessageBodyMember(Order = 1)]
public Stream ByteStream { get; set; }
}
这是我在app.config中使用的绑定配置:
<netTcpBinding>
<binding name=\"TCPConfiguration\" maxReceivedMessageSize=\"67108864\" transferMode=\"Streamed\">
<security mode=\"None\" />
</binding>
</netTcpBinding>
现在,我在想这可能与我使用的绑定类型有关,但我不确定。
解决方法
从注释看来,您似乎有一个问题,一旦开始使用消息协定,就必须对所有参数都使用它们,这意味着您的方法无法返回布尔值,它必须返回另一个消息协定,例如FileUploadResult。
尝试更改它以返回void,并查看它是否已加载,是否确实将其更改为返回归因于消息协定的类。
此MSDN页面上的第一条注释警告此问题,并包含一个可能提供更多信息的链接。
,从根本上讲,这意味着特定操作正在使用消息契约类型和原始类型的组合,并具有以下任意组合:
MixType1: Contract type and primitive types as operation parameters
MixType2: Contract type as a parameter and primitive type as return type
MixType3: Primitive type as a parameter and Contract type as return type
上面列出的任何情况都将产生错误。
更多详细信息:http://www.codeproject.com/Articles/199543/WCF-Service-operations-can-t-be-loaded-due-to-mixi