Hello Expert,
I am trying to build a plugin which calling API and return web response with type Json
How could I catch the message in a specific tag
Here is the json response {"ResultMessage":"Enter a valid date ( from date is before First Hire date)","DocumentNo":0,"Result1":"","Result2":""}
When I am trying to throw the ResultMessage in an exception it gives me the following error
System.Runtime.Serialization.SerializationException: Expecting element 'root' from namespace ''.. Encountered 'None' with name '', namespace ''.
var request = WebRequest.Create(myUri);
request.Method = WebRequestMethods.Http.Post;
var response = request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
ResultMessage refundResponse = new ResultMessage();
DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(ResultMessage));
MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(responseString));
ResultMessage R = deserializer.ReadObject(ms) as ResultMessage;
refundResponse = deserializer.ReadObject(response.GetResponseStream()) as ResultMessage;
throw new InvalidPluginExecutionException(refundResponse.ResultMessage);
[DataContract]
public class ResultMessage
{
[DataMember(Name = "resultmessage")]
public string ResultMessage { get; set; }
[DataMember]
public string Result1 { get; set; }
[DataMember]
public string Result2 { get; set; }
[DataMember]
public int DocumentNo { get; set; }
}
*This post is locked for comments
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156