0
votes

I create a method to receive json string, the method definition is below:

[OperationContract]
string AccessAtomService(string cmd);

It works when I invoke this method by following input:

{
  "receivers": [
    "[email protected]"
  ],
  "subject": "Notification",
  "isHtml": false,
  "content": "Test ok",
  "serviceName": "xxx"
}

But the following json input causes exception:

{
  "receivers": ["[email protected]"],
  "subject": "EMS3000 Notification",
  "isHtml": false,
  "content":"<a href=\"http://www.w3schools.com/html/\">Visit our HTML tutorial</a>",
  "serviceName": "xxx"
}

It seems that any xml element in my json string would cause exception, the exception message from WCF tarce log is:

System.ServiceModel.Dispatcher.NetDispatcherFaultException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

First StackTrace item is:

System.ServiceModel.Dispatcher.PrimitiveOperationFormatter.DeserializeRequest(Message message, Object[] parameters)

Thanks for any help

2

2 Answers

0
votes

Try encoding your content before sending it to the service:

 {
"receivers": ["[email protected]"],
"subject": "EMS3000 Notification",
"isHtml": false,
"content":"&lt;a href=\"http://www.w3schools.com/html/\"&gt;Visit our HTML tutorial&lt;/a&gt;",
"serviceName": "xxx"
}
0
votes

This is because WCF serializes using XML.

So the string you are using is messing with the Deserialization.

MSDN WCF Serialization