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.
我们处于使用ASMX Web服务的传统winforms VB.NET 1.1应用程序的奇怪情况。尝试将用户令牌从WindowsIdentity对象作为参数发送到WebMethod。我将添加一个'HACK:评论。
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'
令牌的类型为IntPtr,第一个问题是生成的WSDL不支持IntPtr,错误为“不支持的类型”
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.
我知道这是一个很大的WTF问题并且听起来不安全,所以任何简单有用的替代方案都是受欢迎的,但是我们如何改变这个系统有很多限制,包括托管环境的复杂性。所以我只想将我们的数据传输到Web服务以节省许多其他麻烦。
Problem 1
Error from WSDL Generation:
WSDL生成错误:
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
另一种方法(扩展WTF因子) - 尝试解决IntPtr问题只是将IntPtr放入System.IO.Stream中使用
BinaryFormatter.Serialize()
on the winforms app end and BF.Deserialize() on the service. But this leads to a new strange issue.
在winforms app端和服务上的BF.Deserialize()。但这导致了一个新的奇怪问题。
Defining the Web Service Method's signature in this fashion:
以这种方式定义Web服务方法的签名:
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...
新的奇怪问题在客户端出现,作为编译错误,就好像Stream的'System.IO'限定被忽略,并被解释为UserService类的一部分......
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 个解决方案
#1
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.
如果由于WSDL缺乏支持而导致IntPtr不起作用,那么请使用Long。 IntPtr可以转换为Integer和Long类型。您可以将值作为这些类型之一传递(最好是Long),然后将其转换回另一端。
Convert to Long
转换为Long
Dim value As Long = token.ToInt64()
Convert from Long
从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.
您应该注意的一件事是令牌仅在创建值的进程的地址空间中有效。如果您通过驻留在另一个进程中的Web服务传递该值,则该令牌将没有任何证明值。它将具有相同的物理地址,但您将无法查询该令牌的值。
#1
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.
如果由于WSDL缺乏支持而导致IntPtr不起作用,那么请使用Long。 IntPtr可以转换为Integer和Long类型。您可以将值作为这些类型之一传递(最好是Long),然后将其转换回另一端。
Convert to Long
转换为Long
Dim value As Long = token.ToInt64()
Convert from Long
从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.
您应该注意的一件事是令牌仅在创建值的进程的地址空间中有效。如果您通过驻留在另一个进程中的Web服务传递该值,则该令牌将没有任何证明值。它将具有相同的物理地址,但您将无法查询该令牌的值。