本文整理匯總了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