views:

369

answers:

1

We're in a strange situation with a legacy winforms VB.NET 1.1 application using ASMX web services. Trying to send a user Token from a WindowsIdentity object as a parameter to a WebMethod. I will be adding a 'HACK: comment.

System.Security.Principal.WindowsIdentity.GetCurrent().Token

The token is of type IntPtr, the first problem is the WSDL being generated doesn't support IntPtr with the error of 'unsupported type'

I'm aware this is a big WTF question and sounds insecure, so any simple helpful alternatives are welcome but there are a lot of constraints on how we can change this system, including complications with the hosting environment. So I would just like to get our piece of data over to the web service to save a lot of other headaches.

Problem 1

Error from WSDL Generation:

Method userClass.TestSendIntPtr can not be reflected. 
--> There was an error reflecting 'token'. 
--> System.IntPtr is an unsupported type.

An alternate approach (extending the WTF factor) - trying to get around the IntPtr issue is to just put the IntPtr into a System.IO.Stream using

BinaryFormatter.Serialize()

on the winforms app end and BF.Deserialize() on the service. But this leads to a new strange issue.

Defining the Web Service Method's signature in this fashion:

Public Class UserService
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function UserToken(ByVal tokenStream As System.IO.Stream) As Boolean

The new strange issue arises on the client end as a compilation error, as if the 'System.IO' qualification of Stream is being ignored, and being interpreted as part of the UserService class...

Problem 2

Value of type 'System.IO.Stream' cannot be converted to 'USERSERVICE.Stream'.

So an answer to either question, or similar alternate approach would be great...

+1  A: 

If an IntPtr won't work because of a lack of support in WSDL, then use a Long instead. IntPtr's are convertible to and from the Integer and Long type. You can just pass around the value as one of these types (preferably Long) and convert it back on the other end.

Convert to Long

Dim value As Long = token.ToInt64()

Convert from Long

Dim token as IntPtr = new IntPtr(value)

One thing that you should note though is that a Token is only valid in the address space of the process that created the value. If you are passing the value through a web service which resides in another process, the token will have no probative value. It will have the same physical address but you will not be able to query values against that token.

JaredPar
Thanks JaredPar, sending the token wasn't going to be useful. The attempt was to recreate the WindowsIdentity on the service. Only because of other difficulties preventing us from connecting to the web service that's correctly setup for integrated security. Recreating it isn't wise/practical/achievable. Thanks for taking the time to provide an answer that supports why this is the wrong approach.
Nick Josevski