使用MessageContract会在启动时崩溃WCF服务

raf*_*ale 6 c# wcf messagecontract wcf-streaming

我正在尝试将MessageContract添加到我的WCF服务,类似于此问题中的内容: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; }
}
Run Code Online (Sandbox Code Playgroud)

这是我在app.config中使用的绑定配置:

  <netTcpBinding>
    <binding name="TCPConfiguration" maxReceivedMessageSize="67108864" transferMode="Streamed">
      <security mode="None" />
    </binding>
  </netTcpBinding>
Run Code Online (Sandbox Code Playgroud)

现在我想这可能与我正在使用的绑定类型有关,但我不完全确定.

Sam*_*der 7

从评论看起来你有问题,一旦你开始使用消息合同,你必须使用它们的所有参数,这意味着你的方法不能返回bool它必须返回另一个消息合同,如说FileUploadResult.

尝试更改它以返回void并查看它是否加载以及是否确实更改它以返回一个归类为消息合同的类.

此MSDN页面上的第一个注释警告此问题,并包含可能提供更多信息的链接.