对于使用 ASMX Web 服务的旧版 winforms VB.NET 1.1 应用程序,我们处于一种奇怪的情况。尝试将 WindowsIdentity 对象中的用户令牌作为参数发送到 WebMethod。我将添加一个'HACK:评论。
System.Security.Principal.WindowsIdentity.GetCurrent().Token
令牌是 IntPtr 类型,第一个问题是生成的 WSDL 不支持 IntPtr,错误为“不支持的类型”
我知道这是一个很大的 WTF 问题,听起来不安全,所以欢迎任何简单有用的替代方案,但我们如何更改这个系统有很多限制,包括托管环境的复杂性。因此,我只想将我们的数据块传输到 Web 服务,以节省很多其他的麻烦。
问题 1
WSDL 生成错误:
Method userClass.TestSendIntPtr can not be reflected.
--> There was an error reflecting 'token'.
--> System.IntPtr is an unsupported type.
另一种方法(扩展 WTF 因素) - 试图解决 IntPtr 问题是将 IntPtr 放入 System.IO.Stream 使用
BinaryFormatter.Serialize()
在 winforms 应用端和服务上的 BF.Deserialize() 上。但这导致了一个新的奇怪问题。
以这种方式定义 Web 服务方法的签名:
Public Class UserService
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function UserToken(ByVal tokenStream As System.IO.Stream) As Boolean
新的奇怪问题出现在客户端作为编译错误,好像 Stream 的“System.IO”资格被忽略,并被解释为 UserService 类的一部分......
问题 2
Value of type 'System.IO.Stream' cannot be converted to 'USERSERVICE.Stream'.
因此,对任何一个问题或类似的替代方法的答案都会很棒......