1 ' Copyright (c) Microsoft Corporation. All Rights Reserved.
4 Imports System
.ServiceModel
5 Imports System
.ServiceModel
.Channels
8 Namespace Microsoft
.ServiceModel
.Samples
10 'The service contract is defined in generatedClient.vb, generated from the service by the svcutil tool.
12 'Client implementation code.
15 Public Shared
Sub Main()
17 Dim binaryData() As Byte = New Byte(999) {}
18 Dim stream
As New MemoryStream(binaryData
)
20 ' Upload a stream of 1000 bytes
21 Dim client
As New UploadClient()
22 Console
.WriteLine(client
.Upload(stream
))
26 ' Compare the wire representations of messages with different payloads
27 CompareMessageSize(100)
28 CompareMessageSize(1000)
29 CompareMessageSize(10000)
30 CompareMessageSize(100000)
31 CompareMessageSize(1000000)
34 Console
.WriteLine("Press <ENTER> to terminate client.")
39 Private Shared
Sub CompareMessageSize(ByVal dataSize
As Integer)
41 ' Create and buffer a message with a binary payload
42 Dim binaryData() As Byte = New Byte(dataSize
- 1) {}
43 Dim msg
As Message
= Message
.CreateMessage(MessageVersion
.Soap12WSAddressing10
, "action", binaryData
)
44 Dim buffer
As MessageBuffer
= msg
.CreateBufferedCopy(Integer.MaxValue
)
46 ' Print the size of a text encoded copy
47 Dim size
As Integer = SizeOfTextMessage(buffer
.CreateMessage())
48 Console
.WriteLine("Text encoding with a {0} byte payload: {1}", binaryData
.Length
, size
)
50 ' Print the size of an MTOM encoded copy
51 size
= SizeOfMtomMessage(buffer
.CreateMessage())
52 Console
.WriteLine("MTOM encoding with a {0} byte payload: {1}", binaryData
.Length
, size
)
58 Private Shared
Function SizeOfTextMessage(ByVal msg
As Message
) As Integer
60 ' Create a text encoder
61 Dim element
As MessageEncodingBindingElement
= New TextMessageEncodingBindingElement()
62 Dim factory
As MessageEncoderFactory
= element
.CreateMessageEncoderFactory()
63 Dim encoder
As MessageEncoder
= factory
.Encoder
65 ' Write the message and return its length
66 Dim stream
As New MemoryStream()
67 encoder
.WriteMessage(msg
, stream
)
68 Dim size
As Integer = CInt(stream
.Length
)
76 Private Shared
Function SizeOfMtomMessage(ByVal msg
As Message
) As Integer
78 ' Create an MTOM encoder
79 Dim element
As MessageEncodingBindingElement
= New MtomMessageEncodingBindingElement()
80 Dim factory
As MessageEncoderFactory
= element
.CreateMessageEncoderFactory()
81 Dim encoder
As MessageEncoder
= factory
.Encoder
83 ' Write the message and return its length
84 Dim stream
As New MemoryStream()
85 encoder
.WriteMessage(msg
, stream
)
87 Dim size
As Integer = CInt(stream
.Length
)