Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of MessageContract crashes WCF service on startup

I'm trying to add a MessageContract to my WCF service, similar to what's going on in this question: WCF: using streaming with Message Contracts

Here's the exception I get: The operation 'UploadFile' could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters.

Here are my contracts:

[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; }
}

And here's the binding configuration I'm using in my app.config:

  <netTcpBinding>
    <binding name="TCPConfiguration" maxReceivedMessageSize="67108864" transferMode="Streamed">
      <security mode="None" />
    </binding>
  </netTcpBinding>

Right now I'm thinking that this may have something to do with the type of binding I'm using, but I'm not entirely sure.

like image 628
rafale Avatar asked May 24 '11 05:05

rafale


1 Answers

From the comments it looks like you have the problem that once you start using message contracts you must use them for all parameters, whcih means your method can't return bool it must return another message contract like say FileUploadResult.

Try changing it to return void and see if it loads and if it does change it to return a class which is attributed as a message contract instead.

The first note on this MSDN page warns about this issue, and contains a link which may provide more information.

like image 162
Sam Holder Avatar answered Nov 04 '22 07:11

Sam Holder