PrincipalPermission on WebMethods

J

Jess

Hi, I am having difficulty in calling an existing wse3.0 web service that has
used declaritive role based authorization on one of its web methods.

----------
The web service looks like the following:
using System;
using System.Web;
using System.Web.Services;
using System.Security;
using System.Security.Permissions;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class MyTestService : System.Web.Services.WebService
{
public MyTestService ()
{
}

[WebMethod]
[SoapDocumentMethod("HelloWorld")]
[PrincipalPermission(SecurityAction.Demand, Role = "SomeRole")]
public string HelloWorld() {
return "Hello World";
}
}

----------
My caller web application is as follows:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Security.Principal;
using Microsoft.Web.Services3;
using Microsoft.Web.Services3.Security.Tokens;
using Microsoft.Web.Services3.Security;
using System.Net;
using System.Threading;
using System.Xml;
using System.Web.Services;
using System.Security.Authentication;

[WebServiceBindingAttribute(Name = "xxxxxxx")]
public partial class WSTest :
Microsoft.Web.Services3.WebServicesClientProtocol
{
public void MakeCall(string username, string password)
{
//create an identity
GenericIdentity ident = new GenericIdentity(username);
string[] roles = { "SomeRole" };

//attach the identity to the principal
GenericPrincipal principal = new GenericPrincipal(ident, roles);

//attach the principal to the thread
Thread.CurrentPrincipal = principal;

//attach the thread to the http context
HttpContext.Current.User = Thread.CurrentPrincipal;

//call the web service
localhost.MyTestService proxy = new localhost.MyTestService();
string x = proxy.HelloWorld();
}
}

----------
I get a "Request for principal permission failed" error when calling the web
service.

Am I missing some key element when setting passing the identity to the web
service? Any ideas?
Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top