Using MessageContract causes WCF service to crash on startup

I am trying to add MessageContract to my WCF service, similar to what happens in this question: WCF: using streaming with Message Contracts

There is an exception: The operation 'UploadFile' cannot 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 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 is the binding configuration I use in my app.config:

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

Now I think that this may have something to do with the type of binding that I use, but I'm not quite sure.

+6
source share
2 answers

From the comments, it seems that you had a problem that as soon as you start using message contracts, you should use them for all parameters, which means that your method cannot return bool, it should return another contract, for example, say FileUploadResult.

Try changing it to return void, and see if it loads, and if it changes it, to return a class that is instead used as a contract with the message.

The first note, this MSDN page warns of this problem and contains a link that may provide additional information.

+7
source

This basically means that a particular operation uses a combination of message contract types and primitive types in any of the following combinations:

 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 

Any of the above scenarios will create an error.

More details: http://www.codeproject.com/Articles/199543/WCF-Service-operations-can-t-be-loaded-due-to-mixi

0
source

Source: https://habr.com/ru/post/888877/


All Articles