Reputation: 3
I have a WCF service that i am using with my mobile application. When i try to pass some parameters to the service it throws an error saying
The server encountered an error processing the request. The exception message is 'The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'InspectVisit'. Encountered unexpected character 'â'.'. See server logs for more details. The exception stack trace is:
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
my service is
[ServiceContract]
public interface ISiteVisitService
{
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest, UriTemplate = "InspectVisit/")]
Output InspectVisit(InspectVisitInput inspectInfo);
}`
And my input class is
[DataContract]
public class InspectVisitInput
{
[DataMember]
public string UserId { get; set; }
[DataMember]
public int VisitId { get; set; }
[DataMember]
public string Catogery { get; set; }
[DataMember]
public string InspectionDate { get; set; }
[DataMember]
public bool ServiceRequired { get; set; }
}
And my json string will loook like this
{
"inspectInfo": {
"UserId":"arun",
"VisitId":39,
"Catogery": “Walks”,
“InspectionDate” : “10/06/2015 11:30:30”,
“ServiceRequired": true
}
}
Anyone please help me here.
Upvotes: 0
Views: 2861
Reputation: 14687
You need to change your JSON to ANSI format. If you copy and paste your JSON to Notepad++ and change the Encoding
to ANSI you'll see your JSON like following:
{
"inspectInfo": {
"UserId":"arun",
"VisitId":39,
"Catogery": “Walksâ€,
“InspectionDate†: “10/06/2015 11:30:30â€,
“ServiceRequired": true
}
}
As you can see in Category
value there's a same character â
that the Exception is showing. The problems seems to be of those different types of quotes "
around the data.
If you have control to modify the JSON then you should change it to ANSI and those special characters by supported ones. Or make sure you mention the UTF-8
encoding for JSON content when sending the data from client.
Upvotes: 1