powered by simpleCommunicator - 2.0.49     © 2025 Programmizd 02
Форумы / WCF, Web Services, Remoting [игнор отключен] [закрыт для гостей] / WebServices & ProgressBar (2)
2 сообщений из 2, страница 1 из 1
WebServices & ProgressBar (2)
    #32755343
Фотография greenapple
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
в продолжение этого топика

столкнулся с необходимостью реализовать то что написано в этой статье: как выяснилось нифига не работает и не могло работать :), но идея хорошая. Поиск по форумам показал, что многие не смогли поправить.
Вот исправленный рабочий вариант, сорри, что VB и мало комментариев
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
'форма-клиент
Public Class Form1
    Inherits System.Windows.Forms.Form

   '...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim pc As New ProgressClient
        pc.Progress = Me.ProgressBar1
        pc.StepDelegate = New ProgressDelegate(AddressOf DoStep)
        pc.StartDelegate = New ProgressDelegate(AddressOf GoStart)
        TextBox1.Text = pc.GetInternalSet().GetXml()
    End Sub

    Private Sub DoStep()
        ProgressBar1.Increment(1)
    End Sub

    Private Sub GoStart()
        ProgressBar1.Value = 0
    End Sub

End Class

'делегат
Public Delegate Sub ProgressDelegate()

'SoapExtension
Imports System.Web
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports System.Web.Services
Imports System.Web.Services.Protocols

Public Class ProgressExtension
    Inherits System.Web.Services.Protocols.SoapExtension

    Private m_bufferIn As Byte()
    Private m_readSize As Integer
    Private m_isAfterSerialization As Boolean
    Private m_oldStream As Stream
    Private m_newStream As Stream

    Public Overloads Overrides Sub ProcessMessage(ByVal message As SoapMessage)
        Select Case message.Stage
            Case SoapMessageStage.AfterSerialize
                m_isAfterSerialization = True
            Case SoapMessageStage.BeforeDeserialize
                Dim clientMessage As SoapClientMessage = CType(message, SoapClientMessage)
                If TypeOf clientMessage.Client Is ProgressClient Then
                    CopyStream(m_oldStream, m_newStream)
                    Dim proxy As ProgressClient = CType(clientMessage.Client, ProgressClient)
                    m_readSize = CInt(m_newStream.Length \ 100)
                    If m_readSize > m_bufferIn.Length - 1 Then ReDim m_bufferIn(m_readSize - 1)
                    m_newStream.Seek(0, System.IO.SeekOrigin.Begin)
                    While True
                        Try
                            Dim bytesRead As Integer = m_newStream.Read(m_bufferIn, 0, m_readSize)
                            If bytesRead = 0 Then
                                m_newStream.Seek(0, System.IO.SeekOrigin.Begin)
                                proxy.StartDelegate.Invoke()
                                Return
                            End If
                            proxy.StepDelegate.Invoke()
                        Catch ex As Exception
                            m_newStream.Seek(0, System.IO.SeekOrigin.Begin)
                            Return
                        End Try
                    End While

                End If
        End Select
    End Sub

    Sub CopyStream(ByVal fromStream As Stream, ByVal toStream As Stream)
        Dim reader As New StreamReader(fromStream)
        Dim writer As New StreamWriter(toStream)
        writer.WriteLine(reader.ReadToEnd())
        writer.Flush()
    End Sub

    Public Overrides Function ChainStream(ByVal stream As Stream) As Stream
        If m_isAfterSerialization = True Then
            m_oldStream = stream
            m_newStream = New MemoryStream
            Return m_newStream
        End If
        Return stream
    End Function

    Public Overloads Overrides Function GetInitializer(ByVal serviceType As Type) As Object
        Return Nothing
    End Function

    Public Overloads Overrides Function GetInitializer(ByVal methodInfo As LogicalMethodInfo, ByVal attribute As SoapExtensionAttribute) As Object
        Return Nothing
    End Function

    Public Overloads Overrides Sub Initialize(ByVal initializer As Object)
        m_bufferIn = New Byte(8192) {}
        m_isAfterSerialization = False
    End Sub
End Class

'обертка для прокси-класса
Imports System.Windows.Forms

Public Class ProgressClient
    Inherits WS.MyService

    Public Progress As ProgressBar
    Public StepDelegate As ProgressDelegate
    Public StartDelegate As ProgressDelegate

End Class


'App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<system.web>
		<webServices>
			<soapExtensionTypes>
				<add type="WindowsApplication2.ProgressExtension, WindowsApplication2" priority="1" group="0" />
			</soapExtensionTypes>
		</webServices>
	</system.web>
</configuration>
...
Рейтинг: 0 / 0
WebServices & ProgressBar (2)
    #32755443
Фотография greenapple
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Public Progress As ProgressBar

вообще не нужна
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / WCF, Web Services, Remoting [игнор отключен] [закрыт для гостей] / WebServices & ProgressBar (2)
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]