[IronPython] Newbie: IronPython and WSE 3.0 (translation from C# example)?

Srivatsn Narayanan srivatsn at microsoft.com
Mon Mar 10 07:27:09 CET 2008


Looks like Webservice.Load is not returning a WebServicesClientProtocol. In the C# world you are instantiating a UserServiceWse. You could do the same in python so:
userService = UserServiceWse()

I assume the definition of that class would look like this:
def UserServiceWse(WebServicesClientProtocol):
        def __init__(self): #The constructor.
                self.blah = foo
                ...

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ramon M. Felciano @ Yahoo
Sent: Sunday, March 09, 2008 11:09 PM
To: users at lists.ironpython.com
Cc: Ramon Felciano
Subject: [IronPython] Newbie: IronPython and WSE 3.0 (translation from C# example)?

Hi --

I'm trying to hook up IronPython to web services secured by Web Services
Enhancements (WSE) 3.0. I have some C# sample code that I'm trying to
convert to Python and am running into some trouble. I'm a C# and Windows
..NET newbie (using IronPython from the commmandline), so the libraries
in question are foreign to me, so I was hoping someone could help me
resolve this. The sample code shows:

--------------------------
using Microsoft.Web.Services3;
using Microsoft.Web.Services3.Design;
using Microsoft.Web.Services3.Security;
using Microsoft.Web.Services3.Security.Tokens;
namespace TpIntegration
{
public class TpPolicy : Policy {
  public TpPolicy() {
    Assertions.Add(new UsernameOverTransportAssertion());
  }
  public static UsernameToken GetUsernameToken(string username, string
password, PasswordOption passwordOption) {
    UsernameToken token = new UsernameToken(username, password,
passwordOption);
    ISecurityTokenManager securityTokenManager =

SecurityTokenManager.GetSecurityTokenManagerByTokenType(WSTrust.TokenTypes.UsernameToken);
    securityTokenManager.CacheSecurityToken(token);
    return token;
  }
  public static void ApplyAutheticationTicket(WebServicesClientProtocol
protocol, string userName, string password) {
    UsernameToken token = GetUsernameToken(userName, password,
PasswordOption.SendPlainText);
    protocol.SetClientCredential(token);
    protocol.SetPolicy(new TpPolicy());
  }
}
}
--------------------------

This is then called using something like this:

--------------------------
UserServiceWse userService = new UserServiceWse();
TpPolicy.ApplyAutheticationTicket(userService, "admin", "admin");
--------------------------

I've taken a swing at converting it:

--------------------------
import Microsoft.Web.Services3
import Microsoft.Web.Services3.Design
import Microsoft.Web.Services3.Security
import Microsoft.Web.Services3.Security.Tokens

def getUsernameToken(username, password, passwordOption):
    token =
Microsoft.Web.Services3.Security.Tokens.UsernameToken(username,
password, passwordOption)
    securityTokenManager =
Microsoft.Web.Services3.Security.Tokens.SecurityTokenManager.GetSecurityTokenManagerByTokenType(Microsoft.Web.Services3.Security.WSTrust.TokenTypes.UsernameToken)
    securityTokenManager.CacheSecurityToken(token)
    return token

def applyAutheticationTicket(protocol, userName, password):
    token = getUsernameToken(userName, password,
Microsoft.Web.Services3.Security.Tokens.PasswordOption.SendPlainText)
    protocol.SetClientCredential(token)
    protocol.SetPolicy(TpPolicy())
--------------------------

but when calling it:

--------------------------
userService =
WebService.Load('http://www.example.com/Services/UserService.asmx')
username = "test"
password = "test"
applyAutheticationTicket(userService, username, password)
--------------------------

I get the following error:

AttributeError: 'UserService' object has no attribute 'SetClientCredential'

Any suggestions on how to debug this further? In case it matters, this
is code from
http://www.targetprocess.com/download/tp20/TP_2_Web_Services_Guide.pdf.

Thanks!

Ramon

_______________________________________________
Users mailing list
Users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list