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

Ramon M. Felciano @ Yahoo felciano at yahoo.com
Mon Mar 10 22:53:02 CET 2008


Got it -- that may be the problem. I generated the stubs as you 
suggested using WseWsdl3.exe (which I assume is the same as the tool you 
mention):

----------------------------------------
C:\Program Files\Microsoft WSE\v3.0\Tools>WseWsdl3.exe /type:webClient 
http://www.example.com/Services/UserService.asmx?wsdl
Web Services Enhancements 3.0 for Microsoft .NET.
 Copyright (c) Microsoft Corporation.

Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.
Writing file 'C:\Program Files\Microsoft WSE\v3.0\Tools\UserService.cs'.
----------------------------------------

The generated C# code does extend the right class:

----------------------------------------
public partial class UserService : 
Microsoft.Web.Services3.WebServicesClientProtocol {
----------------------------------------

but this code does not contain the SetClientCredential or SetPolicy 
methods, which is maybe not surprising giving the partial keyword.

I can't figure out how to do the equivalent in IronPython. If I check 
the type of the returned object, it is of type UserService, and I can't 
introspect it to find it's superclass. Am I correct in assuming that 
there is no equivalent to wsdl.exe for IronPython? I.e. there is no way 
I can use WebServicesHelpers to dump out Python code so I can inspect 
this more directly?

Ramon

Srivatsn Narayanan wrote:
> Well, if the WebService.Load method returned an object that this method then yes this should work. You can use wsdl.exe to generate the proxy in C# (or if u already have the code for UserServiceWse) then you can find out how the call is being made inside the UserServiceWse constructor and translate that to python.
>
>
> -----Original Message-----
> From: Ramon M. Felciano @ Yahoo [mailto:felciano at yahoo.com]
> Sent: Monday, March 10, 2008 10:05 AM
> To: Srivatsn Narayanan
> Cc: Discussion of IronPython
> Subject: Re: [IronPython] Newbie: IronPython and WSE 3.0 (translation from C# example)?
>
> Hi Srivatsn --
>
> Thanks for the quick reply. I don't actually have UserServiceWse defined
> on the python side; I assumed that would be dynamically-generated from
> the WSDL call and that the appropriate methods would be found through
> introspectino. Is that incorrect? Is there some sort of stub-generator I
> need to run in order to auto-generate the UserService client class?
>
> Ramon
>
> Srivatsn Narayanan wrote:
>   
>> 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