I have a Class Library (dll) that calls a web service and includes a form where a I am trying to implement a progress bar using the code in "Adding a Progress Bar to Your Web Service Client Application." The web service executes fine, but I can't get the SoapExtension to fire.

The code for the soap extension is similar to the sample code:


' Progress bar - C# to VB.NET hack


Class ProgressClient

Inherits webapp.MyWebServiceWSE

Public Progress As ProgressBar

Public Transfersize As Integer

Dim MyForm As ServiceForm

Public ProgressDelegate As ServiceForm.UpdateDelegate = AddressOf MyForm.ProgressBarUpdate

End Class


' SOAP Extension - C# to VB.NET hack


Public Class ProgressExtension

Inherits System.Web.Services.Protocols.SoapExtension

' Holds the original stream

Private m_oldStream As Stream

' The new stream

Private m_newStream As Stream

' The buffer for reading from the old stream

' and writing to the new stream

Private m_bufferIn() As Byte

' The progress bar we will be incrementing

Private m_Progress As ProgressBar

' The size of each read

Private m_readSize As Integer

' The delegate we will invoke for updateing

' progress bar

Private m_progressDelegate As ServiceForm.UpdateDelegate

' Used to keep track of which stream we trying

' to chain into

Private m_isAfterSerialization As Boolean

Public Overrides Sub ProcessMessage(ByVal message As System.Web.Services.Protocols.SoapMessage)

Select Case message.Stage

Case Web.Services.Protocols.SoapMessageStage.AfterSerialize

' To let us know that the next ChainStream call

' will let us hook in where we want

m_isAfterSerialization = True

Case Web.Services.Protocols.SoapMessageStage.BeforeDeserialize

' This is where we stream through the data

Dim ClientMessage As SoapClientMessage = CType(message, SoapClientMessage)

If TypeOf ClientMessage.Client Is ProgressClient Then

Dim proxy As ProgressClient = CType(ClientMessage.Client, ProgressClient)

m_Progress = proxy.Progress

' Read 1/100th of the request at a time

' This will give the progress bar 100

' notificications

m_readSize = proxy.Transfersize / 1000

While True


Dim bytesRead As Integer = m_oldStream.Read(m_bufferIn, 0, m_readSize)

If bytesRead = 0 Then

' end of message...rewind the

' memory stream so it is ready

' to be used during deserial.

m_newStream.Seek(0, SeekOrigin.Begin)


End If

m_newStream.Write(m_bufferIn, 0, bytesRead)


Catch ex As Exception

' rewind the memory stream

m_newStream.Seek(0, SeekOrigin.Begin)


End Try

End While

End If

End Select

End Sub

Public Overrides Function ChainStream(ByVal stream As System.IO.Stream) As System.IO.Stream

If m_isAfterSerialization Then

m_oldStream = stream

m_newStream = New MemoryStream

ReDim m_bufferIn(8192)

End If

Return MyBase.ChainStream(stream)

End Function

Public Overloads Overrides Function GetInitializer(ByVal serviceType As System.Type) As Object

Return Nothing

End Function

Public Overloads Overrides Function GetInitializer(ByVal methodInfo As System.Web.Services.Protocols.LogicalMethodInfo, ByVal attribute As System.Web.Services.Protocols.SoapExtensionAttribute) As Object

Return Nothing

End Function

Public Overrides Sub Initialize(ByVal initializer As Object)

m_isAfterSerialization = False

End Sub

End Class

I think the problem has something to do with app.config file. I have tried adding the extension both ways (with and without the Public Key Token) Here is what I have:




<add type="WebClient.ProgressExtension, "WebClient" priority="1" group="High"/>

<add type=""WebClient.ProgressExtension, "WebClient, Version=, Culture=neutral, PublicKeyToken=94f7ceaebb8617d0" priority="1" group="High"/>



<add type="Microsoft.Web.Services3.Description.WseExtensionImporter, Microsoft.Web.Services3, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />





<add assembly="Microsoft.Web.Services3, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />




It occurs to me that the problem has either to do with running the project in the debugger because the of how the object is referenced or maybe WSE 3.0.

Re: .NET Remoting and Runtime Serialization Trouble with SoapExtension not firing.

Sowmy Srinivasan

Please file it in the asxm& werbservice forum at ForumID=46&SiteID=1