.NET Framework Bookmark and Share   
 index > ASMX Web Services and XML Serialization > problem using SOAPExtension with WSE 3.0 MTOM Encoding
 

problem using SOAPExtension with WSE 3.0 MTOM Encoding

Hi All,

Maybe someone can shed some light on this. I am writing a web service, that amongst other things allows the uploading of files, and hence I use MTOM encoding with WSE 3.0. I also use a SoapExtension to log the request and response on the web service. I leave the server mode of MTOM to optional.

On my Client Application that consumes the web service, if I set the Client Mode to Off, the SOAP extension works and logs the request and response.
If I turn Client Mode to On on the Client application, the SOAP extension logs the request properly, but when I try to log the response (as a Stream), the stream is empty.

Is there a reason why when MTOM encoding is switched on that the SOAP Extension streams will be effected?

Thanks for any insight.
Waggles
I came across the same issue. It is caused by the MTOM ASP.NET code, which closes (and sometimes even disposes) streams in the SoapExtension pipeline. SoapExtensions are expressly forbidden from closing streams passed to them during SOAP pipeline processing. I haven't seen any posts by Microsoft addressing this issue. I'll do some more digging, to see if a workaround is possible.
tf619
I'm running into the same issue w/ WSE 3.0 , MTOM and Soap Extensions as well.

I have a SOAP extension which will log any exceptions and works fine with any non-MTOM methods.

I have a method which uses MTOM to upload an image and return a string, when the response is generated, in the AfterSerialize stage the response stream appears to die and of course an exception is thrown on the client side about the ContentType being empty.

Anyone have any ideas on this one?
Lance Lambert
I came across the same issue. It is caused by the MTOM ASP.NET code, which closes (and sometimes even disposes) streams in the SoapExtension pipeline. SoapExtensions are expressly forbidden from closing streams passed to them during SOAP pipeline processing. I haven't seen any posts by Microsoft addressing this issue. I'll do some more digging, to see if a workaround is possible.
tf619
See Below
  • Proposed As Answer byWVDev_35 Monday, September 21, 2009 3:20 PM
  •  
WVDev_35

I have created a web service that use MTOM for file transfer and also has a web extension for handling exceptions.They both seem to workindependentlybut when used together problems arise.

I noticed that MTOM closes the m_applicationStream before the AfterSerilize Process stage has been reach. A solution was to create an inherited Memory Stream that refused to called base close method, this way the m_applicationStream is still open and usable. This is the inherited MemoryStream. The close method isoverriddento prevent the base stream from being closed. It is also overloaded to provide a way of closing the base stream if required. Finally the base Dispose method is hidden, and a new version is provided that close the base stream before calling the disposemethodso that we can make sure everything is cleaned up.

Class ExtMemoryStream
    Inherits System.IO.MemoryStream

    ''' <summary>
    '''   Overriden close method.
    ''' </summary>
    ''' <remarks>Does nothing.</remarks>
    <Obsolete("This method does not close the stream.")> _
    Public Overloads Overrides Sub Close()
    End Sub

    ''' <summary>
    '''   Closes the current stream and releases any resources (such as sockets and
    '''   file handles) associated with the current stream.
    ''' </summary>
    ''' <param name="close">True if the Stream should be closed.</param>
    Public Overloads Sub Close(ByVal close As Boolean)
        If close Then
            MyBase.Close()
        End If
    End Sub

    ''' <summary>
    '''   Releases all resources used by the System.IO.Stream.
    ''' </summary>
    Public Shadows Sub Dispose()
        ' Close the stream, as the base Dispose cannot call Close anymore
        MyBase.Close()
        MyBase.Dispose()
    End Sub
End Class


Now I am getting the following message that I can't find anywhere and am not sure how to solve. Please help.

Exception Type: System.FormatException
Exception Message: WSE2202: The stream is not in a valid format.
Exception Source: Microsoft.Web.Services3
  • Proposed As Answer byWVDev_35 Monday, September 21, 2009 5:46 PM
  •  
WVDev_35

You can use google to search for other answers

Custom Search

More Threads

• A web service to return user interface components from applications for the purposes of writing user guidelines
• Browsable WSE 3.0 secured web service
• Create virtual directory through code (web service) - Access denied exception
• NetDispatchedFaultException when receiving file over 800Kb
• HTTP Handlers
• The underlying connection was closed: A connection that was expected to be kept alive was closed by the server
• Web Service has no dll generated
• Soap fault handling from Java WebServices
• Web Service Snafu
• Creating the Fault Variables in WSDL.