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)

"Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

(0) ShareShare
ReportReport
Posted on by

Hi all,

Please help me to solve this problem..

im trying to call my web API from my plugin but its thowing this exception

{"Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."}

And My Code Is:

HttpWebRequest request = WebRequest.Create("http://localhost:xxxx/api/CRM") as HttpWebRequest;
request.Method = "Post";
request.KeepAlive = false;
request.Timeout = 20000;
byte[] dataByte = Encoding.ASCII.GetBytes(Json);
request.ContentLength = dataByte.Length;
request.ContentType = "application/json";
Stream dataStream = request.GetRequestStream();
dataStream.Write(dataByte, 0, dataByte.Length);
dataStream.Close();
HttpWebResponse POSTResponse = request.GetResponse() as HttpWebResponse; //Get response from server
StreamReader reader = new StreamReader(POSTResponse.GetResponseStream());
reader.Close();

*This post is locked for comments

I have the same question (0)
  • Nithya Gopinath Profile Picture
    17,078 on at

    Hi Harshad,

    Refer the following thread to fix this error.

    https://community.dynamics.com/crm/f/117/t/144242

    If found useful, please mark as verified.

    Thanks

  • Community Member Profile Picture
    on at

    this one is not working .. im calling my plugin from dat plugin im calling web API but its throwing this error

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hello,

    Please refer this thread too.

    community.dynamics.com/.../163274

    Thanks

  • Community Member Profile Picture
    on at

    is there any way to use the sandbox plugin to call the web APIs?

  • Community Member Profile Picture
    on at

    Hi Nithya,

    is there any way to use the sandbox plugin to call the web APIs?

    Thanks

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Harshad,

    I think the following blog clears your doubt.

    debajmecrm.com/.../knowhow-can-we-make-web-api-calls-from-plugins-in-dynamics-crm-2016

    Thanks

  • Community Member Profile Picture
    on at

    Hi,

    I'm trying to create httpwebrequest and I still getting an Error.

    this is my code:

    var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://test/requests");

               httpWebRequest.ContentType = "application/json";

               httpWebRequest.Method = "POST";

               httpWebRequest.Accept = "application/json";

               httpWebRequest.Headers.Add("x-api-key", "Test");

               using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))

               {    

                   string json = "{" +

                   "customer" + ": {" +

                      "name" + ":" + "firstname" +

                       "," + "email" + ":" + "test@test.com" +

                   "}," +

                   "brand" + ":" + "Name" + "," +

                   "employee" + ": {" +

                     "custom_id" + ":" + "123"+                

                  " }," +

                   "channel" + ":" + "phone" + "}";

                   streamWriter.Write(json);

                   streamWriter.Flush();

                   streamWriter.Close();

               }

               var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

               using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))

               {

                   var result = streamReader.ReadToEnd();                              

               }

    please tell me what is the problem and what should I do.

    thank you.

  • Meenakshi55 Profile Picture
    on at

    Hi harshad,

    I am also facing this type of issue while transfer file to FTP server. In sandbox plugin ,API is being called but throwing error -"System.Net.WebPermission, failed". Please suggest what to do.

    Thanks in advance.

  • Community Member Profile Picture
    on at

    Hi Meeanakshi,

    You want to register the plugin as none instead of sandbox, for debugging purpose and registering purpose and it will surely work.


    Thanks
    Harshad Ahammed

  • Community Member Profile Picture
    on at

    Hi Adva,

    Your code seems to be have no problem, have you registered the plugin as sand-box or none. please verify that if it is sandbox you cant call external API, so if the plugin is registered with sandbox please change it and it will work surely.

    Thanks

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 March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
Mark Eckert Profile Picture

Mark Eckert 2

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans