Skip to main content

Notifications

Announcements

No record found.

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 Microsoft Employee

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: "Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

    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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: "Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

    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

  • Meenakshi55 Profile Picture
    Meenakshi55 on at
    RE: "Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

    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
    Community Member Microsoft Employee on at
    RE: "Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

    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.

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: "Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

    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
    Community Member Microsoft Employee on at
    RE: "Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

    Hi Nithya,

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

    Thanks

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: "Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

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

  • Verified answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: "Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

    Hello,

    Please refer this thread too.

    community.dynamics.com/.../163274

    Thanks

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: "Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

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

  • Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: "Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

    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

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,375 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans