本文整理汇总了VB.NET中System.ServiceModel.OperationBehaviorAttribute.Impersonation属性的典型用法代码示例。如果您正苦于以下问题:VB.NET OperationBehaviorAttribute.Impersonation属性的具体用法?VB.NET OperationBehaviorAttribute.Impersonation怎么用?VB.NET OperationBehaviorAttribute.Impersonation使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.ServiceModel.OperationBehaviorAttribute
的用法示例。
在下文中一共展示了OperationBehaviorAttribute.Impersonation属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: New
' 导入命名空间
Imports System.ServiceModel
Imports System.Threading
Namespace Microsoft.WCF.Documentation
<ServiceContract(Name:="SampleHello", Namespace:="http://microsoft.wcf.documentation")> _
Public Interface IHello
<OperationContract> _
Function Hello(ByVal greeting As String) As String
End Interface
Public Class HelloService
Implements IHello
Public Sub New()
Console.WriteLine("Service object created: " & Me.GetHashCode().ToString())
End Sub
Protected Overrides Sub Finalize()
Console.WriteLine("Service object destroyed: " & Me.GetHashCode().ToString())
End Sub
<OperationBehavior(Impersonation:=ImpersonationOption.Required)> _
Public Function Hello(ByVal greeting As String) As String Implements IHello.Hello
Console.WriteLine("Called by: " & Thread.CurrentPrincipal.Identity.Name)
Console.WriteLine("IsAuthenticated: " & Thread.CurrentPrincipal.Identity.IsAuthenticated.ToString())
Console.WriteLine("AuthenticationType: " & Thread.CurrentPrincipal.Identity.AuthenticationType.ToString())
Console.WriteLine("Caller sent: " & greeting)
Console.WriteLine("Sending back: Hi, " & Thread.CurrentPrincipal.Identity.Name)
Return "Hi, " & Thread.CurrentPrincipal.Identity.Name
End Function
End Class
End Namespace
示例2: Run
' 导入命名空间
Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports System.Security.Principal
Imports System.Threading
Namespace Microsoft.WCF.Documentation
Public Class Client
Public Sub Run()
' Picks up configuration from the config file.
Dim wcfClient As New SampleHelloClient()
Try
' Set the client credentials to permit impersonation. You can do this programmatically or in the configuration file.
wcfClient.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation
' Make calls using the proxy.
Console.ForegroundColor = ConsoleColor.White
Console.WriteLine("Enter a greeting to send and press ENTER: ")
Console.Write(">>> ")
Console.ForegroundColor = ConsoleColor.Green
Dim greeting = Console.ReadLine()
Console.ForegroundColor = ConsoleColor.White
Console.WriteLine("Called service with: " & vbCrLf & vbTab & greeting)
Console.WriteLine("Service returned: " & wcfClient.Hello(greeting))
Console.ForegroundColor = ConsoleColor.Blue
Console.Write("Press ")
Console.ForegroundColor = ConsoleColor.Red
Console.Write("ENTER")
Console.ForegroundColor = ConsoleColor.Blue
Console.Write(" to exit...")
Console.ReadLine()
wcfClient.Close()
Catch timeProblem As TimeoutException
Console.WriteLine("The service operation timed out. " & timeProblem.Message)
wcfClient.Abort()
Console.Read()
Catch commProblem As CommunicationException
Console.WriteLine("There was a communication problem. " & commProblem.Message)
wcfClient.Abort()
Console.Read()
End Try
End Sub
Public Shared Sub Main()
Dim client As New Client()
client.Run()
End Sub
End Class
End Namespace