Reputation: 6726
Calling the following method on my wcf service….
ObservableCollection<PatientViewModel> Search(List<string> searchTerms, SearchNature nature, SearchMode mode, List<SearchField> fields)
Result in the following exception…
ProtoBuf.ProtoException, protobuf-net, Version=2.0.0.627, Culture=neutral, PublicKeyToken=75e2634e27c46854
Invalid wire-type; this usually means you have over-written a file without truncating or setting the length; see http://stackoverflow.com/q/2152978/23354
ProtoBuf.ProtoReader.ReadInt32()
proto_4(Object , ProtoReader )
ProtoBuf.ServiceModel.XmlProtoSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName)
System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.PartInfo.ReadObject(XmlDictionaryReader reader, XmlObjectSerializer serializer)
System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)
System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameters(XmlDictionaryReader reader, PartInfo[] parts, Object[] parameters, Boolean isRequest)
System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)
System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)
System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc)
System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
NOTE: If I remove the 2nd and 3rd parameters. So the method is…
ObservableCollection<PatientViewModel> Search(List<string> searchTerms, List<SearchField> fields)
This works fine.
The parameter fields is an enum list and that deserializes with no issue.
Why would a single enum value cause the above exception?
Thanks in advance.
For your reference...
[DataContract]
public enum SearchNature
{
[EnumMember] None,
[EnumMember] Letters,
[EnumMember] Numbers
}
[DataContract]
public enum SearchMode
{
[EnumMember] None,
[EnumMember] BeginsWith,
[EnumMember] Contains
}
[DataContract]
public enum SearchField
{
[EnumMember] None,
[EnumMember] FirstName,
[EnumMember] LastName,
[EnumMember] PatientId,
[EnumMember] PriorId,
[EnumMember] PhoneNumber,
[EnumMember] DateOfBirth
}
Edit:
Additionally, if I change ProtoOperationBehavior to use the default serializer when the type is an enum instead of XmlProtoSerializer, the service calls work fine.
public override XmlObjectSerializer CreateSerializer(Type type, System.Xml.XmlDictionaryString name, System.Xml.XmlDictionaryString ns, IList<Type> knownTypes)
{
if (type.IsEnum) return base.CreateSerializer(type, name, ns, knownTypes);
if (model == null) throw new InvalidOperationException("No Model instance has been assigned to the ProtoOperationBehavior");
return XmlProtoSerializer.TryCreate(model, type) ?? base.CreateSerializer(type, name, ns, knownTypes);
}
Upvotes: 0
Views: 3925
Reputation: 4768
If you make a class and pass that into your search instead you should get what you need. Hopefully this will help.
If you then have the serializer in place it will give you back an operational class object.
[ProtoContract()]
public class PatientSearch
{
public PatientSearch()
{
searchTerms = new List<string>();
fields = new List<SearchField>();
}
[ProtoMember(1)]
public List<string>searchTerms {get;private set;}
[ProtoMember(2)]
public SearchNature Nature {get; set;}
[ProtoMember(3)]
public SearchMode Nature {get; set;}
[ProtoMember(4)]
public List<SearchField> fields {get; private set;}
}
Upvotes: 0
Reputation: 79551
Enums, int, double, string, etc are not valid protocol buffer messages by themselves. You have to make them fields or properties of an object and then serialize that object.
Upvotes: 1