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

Srivatsn Narayanan srivatsn at microsoft.com
Wed Mar 12 07:58:30 CET 2008


I looked at the code for the DynamicWebServiceHelpers sample on codeplex and it doesn't seem to deal with WSE3.0. So I guess the proxy that is generated by WebService.Load will not derive from WebServicesClientProtocol but from whatever is the base class for the old web services(I think it's SOAPHttpClientProtocol). I guess you could do one of two things. Compile your generated proxy(UserService.cs) into a dll and then use that from python
Or port UserService.cs to python. You probably don't need the entire thing. My guess is that if u just set the url it might actually work - something like:
userService = WebServicesClientProtocol()
userService.Url = "http://www.example.com/Services/UserService.asmx"
TpPolicy.ApplyAutheticationTicket(userService, "admin", "admin")


-----Original Message-----
From: Ramon M. Felciano @ Yahoo [mailto:felciano at yahoo.com]
Sent: Tuesday, March 11, 2008 9:11 PM
To: Srivatsn Narayanan
Cc: Discussion of IronPython
Subject: Re: [IronPython] Newbie: IronPython and WSE 3.0 (translation from C# example)?

Hi Srivatsn --

Thanks! Here's the constructor for the C# code:

------------------------
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;

//
// This source code was auto-generated by wsdl, Version=2.0.50727.42.
//

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="UserServiceSoap",
Namespace="http://targetprocess.com")]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(DataTransferObject))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(object[]))]
public partial class UserService :
Microsoft.Web.Services3.WebServicesClientProtocol {
    private System.Threading.SendOrPostCallback
RetrieveAllForDefaultRoleOperationCompleted;
    private System.Threading.SendOrPostCallback GetByIDOperationCompleted;
    private System.Threading.SendOrPostCallback CreateOperationCompleted;
    private System.Threading.SendOrPostCallback UpdateOperationCompleted;
    private System.Threading.SendOrPostCallback DeleteOperationCompleted;
    private System.Threading.SendOrPostCallback
RetrieveAllOperationCompleted;
    private System.Threading.SendOrPostCallback RetrieveOperationCompleted;
    private System.Threading.SendOrPostCallback
RetrievePageOperationCompleted;
    private System.Threading.SendOrPostCallback
RetrieveCountOperationCompleted;

    /// <remarks/>
    public UserService() {
        this.Url =
"http://ingenuity.tpondemand.com/Services/UserService.asmx";
    }
------------------------

On the python side, I'm trying to generate this dynamically using

------------------------
import clr
clr.AddReference("DynamicWebServiceHelpers.dll")
from DynamicWebServiceHelpers import *
userService =
WebService.Load('http://www.example.com/Services/UserService.asmx')
------------------------

Any ideas?

Ramon



Srivatsn Narayanan wrote:
> In the C# side you are using the constructor of UserService to create an instance of WebServicesClientProtocol. In the python side, you don't seem to be creating an instance of this. You can have a look at the constructor of the generated C# UserService and see how the instance is created and translate that to python. If you are having trouble with that post the constructor code here.
>
> Srivatsn
>
> -----Original Message-----
> From: Ramon M. Felciano @ Yahoo [mailto:felciano at yahoo.com]
> Sent: Monday, March 10, 2008 2:53 PM
> To: Srivatsn Narayanan
> Cc: Discussion of IronPython
> Subject: Re: [IronPython] Newbie: IronPython and WSE 3.0 (translation from C# example)?
>
> 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