web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Call API , Return Json

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans