Hi all,
I have written a plugin wherein I am trying to get an XML response.
This is my code :
// Set the Method property of the request to POST. string strXMLServer = "xxx"; var request = (HttpWebRequest)WebRequest.Create(strXMLServer); request.Method = "POST";
// Set the ContentType property of the WebRequest. request.ContentType = "xyz"; // Assuming XML is stored in strXML byte[] byteArray = Encoding.UTF8.GetBytes(strXML);
// Set the ContentLength property of the WebRequest. request.ContentLength = byteArray.Length;
//(LINE 5) Get the request stream
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
This code works fine when its written in a console application. But when I copy the same code to a class library(plugin) and tries to debug it using plugin profiler, the application gets stopped abruptly when it reaches (LINE 5)
i.e. At Stream dataStream = request.GetRequestStream();
NOTE: I am using Dynamics 365 online trial version
Any help would be appreciated :)
Thanks in advance
*This post is locked for comments
Hi Mehatin, i have the same issue. Kindly did same thing like u did, still i have the issue, my tool stops working.
My Code
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.Headers.Add("Authorization: " + "Bearer" + " " + KEY);
request.ContentLength = data.Length;
Stream stream = request.GetRequestStream();
{
stream.Write(data, 0, data.Length);
}
var response = (HttpWebResponse)request.GetResponse(); //error tool crashes, i took off the debugger also.
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
}
Hi! I know a plugin that can help log calls automatically in MS Dynamics. That app is Tenfold, a CTI and sales acceleration platform that offers features like call logging and call monitoring. You can check out Tenfold on the integrations page if you'd like to know more. www.tenfold.com/.../dynamics
Hi samhitha,
Thanks for the response. The debugger is not supported in LINE5 and it gets stopped abruptly. I have changed the breakpoint after the GetRequestStream() function and it worked. I found that many people are facing the same issue. Hope this issue gets noticed and solved.
Hi Meharin Sherif
I faced the same issue while calling the web API methods using plugin.
I used the same code u did for Dynamics 365 online trial, and GetRequestStream() worked for me.
Make sure you set content.length=0, when the strXML is null. it will be better if you can return the response from a function or use tracing service to log it.
Please don't put the debugger on the Line 5 when using profiler as it is getting crashed for me too. Skip that line and you can check the returned response.
I did something like this with JSON. You can use xml serializer instead of JSON. I am using classes for request and response objects here.
string streamData = "";
using (MemoryStream stream = new MemoryStream())
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ResponseClass));
serializer.WriteObject(stream, responseObject);
stream.Position = 0;
using (StreamReader reader = new StreamReader(stream))
{
streamData = reader.ReadToEnd();
}
}
Hello Mohd Saad Akhtar,
Thanks for your response.
But this link also uses request.GetRequestStream() function for XML request. The issue is, when it reaches this function plugin gets stopped abruptly. It works fine with console application. Any idea why this happens?
Refer this:
www.greenbeacon.com/.../invoke-external-web-service-from-ms-crm-2011-plugin
https://softnovation.wordpress.com/2016/08/02/consume-web-service-from-plugin/
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,104 Most Valuable Professional
nmaenpaa 101,156