我试图在我的WCF服务中添加一个MessageContract,类似于这个问题中发生的事情:WCF:使用流与消息契约
下面是我得到的例外:操作'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>现在,我认为这可能与我使用的绑定类型有关,但我不完全确定。
发布于 2011-05-24 06:26:53
从注释中可以看出,您的问题是,一旦您开始使用消息契约,您必须将它们用于所有参数,这意味着您的方法不能返回bool --它必须返回另一个消息契约,比如FileUploadResult。
尝试将其更改为返回void,并查看它是否加载,以及是否将其更改为返回一个类,该类被归为消息契约。
此MSDN页面上的第一个注意事项警告这个问题,并包含一个可能提供更多信息的链接。
发布于 2014-04-10 18:38:39
这基本上意味着一个特定的操作在以下任何一个组合中使用消息契约类型和基本类型的组合:
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
https://stackoverflow.com/questions/6106299
复制相似问题