Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Error while calling a web method (web service) from a web part

  Asked By: Roland    Date: Jan 13    Category: Sharepoint    Views: 4966

I am receiving the following error which trying to access a web service
from a web part. It is actually a security error. Could anyone please help me. I
have to complete this by this week.

System.Security.SecurityException: Request for the permission of type
System.Net.WebPermission, System, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 failed. at
System.Security.CodeAccessSecurityEngine.CheckHelper(PermissionSet grantedSet,
PermissionSet deniedSet, CodeAccessPermission demand, PermissionToken permToken)
at System.Security.CodeAccessSecurityEngine.Check(PermissionToken permToken,
CodeAccessPermission demand, StackCrawlMark& stackMark, Int32 checkFrames, Int32
unrestrictedOverride) at
System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap,
StackCrawlMark& stackMark) at System.Security.CodeAccessPermission.Demand() at
System.Net.HttpRequestCreator.Create(Uri Uri) at
System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase) at
System.Net.WebRequest.Create(Uri requestUri) at
System.Web.Services.Protocols.WebClientProtocol.GetWebRequest(Uri uri) at
System.Web.Services.Protocols.HttpWebClientProtocol.GetWebRequest(Uri uri) at
System.Web.Services.Protocols.SoapHttpClientProtocol.GetWebRequest(Uri uri) at
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName,
Object[] parameters) at TestPrint.WebReference.exponentWSA.AddJob(String
jobInfo, String jobTicket) in c:\documents and settings\ramprasad\my
documents\visual studio projects\testprint\web
references\webreference\reference.cs:line 37 at
TestPrint.TestPrint._myButton_click(Object sender, EventArgs e) in c:\documents
and settings\ramprasad\my documents\visual studio
projects\testprint\testprint.cs:line 504

The line 504 is: string strXML =

Addjod(string,string) is a webmethod.



2 Answers Found

Answer #1    Answered By: Donald Torres     Answered On: Jan 13

Did u set the security  settings before consuming the web  service?

membersListWs.Lists MyWebService=new membersListWs.Lists();

Answer #2    Answered By: Courtney Scott     Answered On: Jan 13

Check the trust level in the web.config file.

<trust level="*Full*" originUrl="" /> <!-- not a good idea, later create
your custom policy and trust level -->

Its not good to set your trust level full, you can create your custom trust
level there are articles about CAS in blogs and msdn.