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

Ramon M. Felciano @ Yahoo felciano at yahoo.com
Mon Mar 10 07:09:11 CET 2008


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




More information about the Ironpython-users mailing list