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; }
[MessageHea开发者_如何学编程der(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.
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.
This basically means that a particular operation is using 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 scenarios listed above would generate the error.
More details: http://www.codeproject.com/Articles/199543/WCF-Service-operations-can-t-be-loaded-due-to-mixi
精彩评论