/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
samples/snippets/visualbasic/VS_Snippets_CFX/faultcontractattribute/vb/services.vb
58 строк
2 KB
Next Turn
Format codes based on .editorconfig, Part 4 (#18853)
08 июн 2020, 22:49
Не верифицирован
08 июн 2020, 22:49
7e34efc
Код
Авторство
О чём код?
' <snippet1> Imports System.Collections.Generic Imports System.Net.Security Imports System.Runtime.Serialization Imports System.ServiceModel Imports System.Text Namespace Microsoft.WCF.Documentation <ServiceContract(Namespace:="http://microsoft.wcf.documentation")> _ Public Interface ISampleService ' <snippet4> <OperationContract, FaultContractAttribute(GetType(GreetingFault), Action:="http://www.contoso.com/GreetingFault", ProtectionLevel:=ProtectionLevel.EncryptAndSign)> _ Function SampleMethod(ByVal msg As String) As String ' </snippet4> End Interface <DataContractAttribute> _ Public Class GreetingFault Private report As String Public Sub New(ByVal message As String) Me.report = message End Sub <DataMemberAttribute> _ Public Property Message() As String Get Return Me.report End Get Set(ByVal value As String) Me.report = value End Set End Property End Class Friend Class SampleService Implements ISampleService #Region "ISampleService Members" Public Function SampleMethod(ByVal msg As String) As String Implements ISampleService.SampleMethod Console.WriteLine("Client said: " & msg) ' Generate intermittent error behavior. Dim rand As New Random(DateTime.Now.Millisecond) Dim test As Integer = rand.Next(5) If test Mod 2 <> 0 Then Return "The service greets you: " & msg Else ' <snippet5> Throw New FaultException(Of GreetingFault)(New GreetingFault("A Greeting error occurred. You said: " & msg)) End If ' </snippet5> End Function #End Region End Class End Namespace ' </snippet1>