web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • Community Member Profile Picture
    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
    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
    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
    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
    17,078 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
    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
    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
    17,078 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
    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
    17,078 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans