當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET OperationContextScope類代碼示例

本文整理匯總了VB.NET中System.ServiceModel.OperationContextScope的典型用法代碼示例。如果您正苦於以下問題:VB.NET OperationContextScope類的具體用法?VB.NET OperationContextScope怎麽用?VB.NET OperationContextScope使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了OperationContextScope類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: Client

' 導入命名空間
Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports System.Threading

Public Class Client
    Implements ISampleServiceCallback
  Private wait As ManualResetEvent = Nothing

  Private Sub New()
    Me.wait = New ManualResetEvent(False)
  End Sub

  Public Shared Sub Main()
    Dim client As New Client()
    client.Run()
  End Sub

  Private Sub Run()
    ' Picks up configuration from the config file.
    Dim wcfClient As New SampleServiceClient(New InstanceContext(Me))
    Try
      Using scope As New OperationContextScope(wcfClient.InnerChannel)
                Dim header As MessageHeader = MessageHeader.CreateHeader("Service-Bound-CustomHeader", _
                                    "http://Microsoft.WCF.Documentation", "Custom Happy Value.")
        OperationContext.Current.OutgoingMessageHeaders.Add(header)

        ' Making calls.
        Console.WriteLine("Enter the greeting to send: ")
        Dim greeting As String = Console.ReadLine()

        'Console.ReadLine();
                header = MessageHeader.CreateHeader("Service-Bound-OneWayHeader", _
                                                    "http://Microsoft.WCF.Documentation", "Different Happy Value.")
        OperationContext.Current.OutgoingMessageHeaders.Add(header)

        ' One-way
        wcfClient.Push(greeting)
        Me.wait.WaitOne()

        ' Done with service. 
        wcfClient.Close()
        Console.WriteLine("Done!")
        Console.ReadLine()
      End Using
    Catch timeProblem As TimeoutException
      Console.WriteLine("The service operation timed out. " & timeProblem.Message)
      Console.ReadLine()
      wcfClient.Abort()
    Catch commProblem As CommunicationException
      Console.WriteLine("There was a communication problem. " & commProblem.Message)
      Console.ReadLine()
      wcfClient.Abort()
    End Try
  End Sub


  #Region "ISampleServiceCallback Members"

  Public Sub PushBack(ByVal msg As String) Implements ISampleServiceCallback.PushBack
    Console.WriteLine("Service said: " & msg)
    Me.WriteHeaders(OperationContext.Current.IncomingMessageHeaders)
    Me.wait.Set()
  End Sub

  Private Sub WriteHeaders(ByVal headers As MessageHeaders)
    Console.ForegroundColor = ConsoleColor.Red
    Console.WriteLine("IncomingHeader:")
    Console.ForegroundColor = ConsoleColor.Blue
    For Each h As MessageHeaderInfo In headers
      If Not h.Actor.Equals(String.Empty) Then
        Console.WriteLine(vbTab & h.Actor)
      End If
      Console.ForegroundColor = ConsoleColor.White
      Console.WriteLine(vbTab & h.Name)
      Console.ForegroundColor = ConsoleColor.Blue
      Console.WriteLine(vbTab & h.Namespace)
      Console.WriteLine(vbTab & h.Relay)
      If h.IsReferenceParameter = True Then
        Console.WriteLine("IsReferenceParameter header detected: " & h.ToString())
      End If
    Next h
    Console.ResetColor()
  End Sub
  #End Region

End Class
開發者ID:VB.NET開發者,項目名稱:System.ServiceModel,代碼行數:87,代碼來源:OperationContextScope


注:本文中的System.ServiceModel.OperationContextScope類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。