By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,830 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,830 IT Pros & Developers. It's quick & easy.

SOAP Extension error-Value cannot be null

P: n/a
I have created a simple Client-side SOAP Extension for a webclass that I
have. When I apply the extension attribute to the the calling function in the
proxy class I get an error 'Value cannot be null'. When the extension
attribute is not applied it runs fine. The wierd thing is that it does not
appear to be an error within the SOAP extension because I break-pointed it
and when the proxy function gets called the SOAP extension runs fine. After
the end of the subroutine in the SOAP extension it returns back to run the
proxy function and gets an error on the actual call to the webservice. Here
is the function call in the proxy:

'<remarks/>
<SoapDisplayExtension(), _
System.Web.Services.Protocols.SoapDocumentMethodAt tribute( _
"http://tempuri.org/BugTracker2/Service1/GetBug" _
, RequestNamespace:="http://tempuri.org/BugTracker2/Service1" _
, ResponseNamespace:="http://tempuri.org/BugTracker2/Service1" _
, Use:=System.Web.Services.Description.SoapBindingUs e.Literal _
,
ParameterStyle:=System.Web.Services.Protocols.Soap ParameterStyle.Wrapped)> _
Public Function GetBug(ByVal BugID As Integer) As Bug
Dim results() As Object
results = Me.Invoke("GetBug", New Object() {BugID})
Return CType(results(0), Bug)
End Function

The error occurs on this line: results = Me.Invoke("GetBug", New
Object() {BugID})

The error is: Unhandled exception of type 'System.ArgumentNullException'
occured in mscorlib.dll. Addition infomation: Value cannot be null

If I remove the attribute: SoapDisplayExtension(), then this line runs fine.

Any ideas?

Thanks!!

PS here is the SOAP extension code and attribute code:

Imports System.IO
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml
Imports System.Xml.Xsl

Public Class SoapDisplayExtension
Inherits SoapExtension

Private originalStream As Stream
Private internalStream As Stream

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

End Function

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

End Function

Public Overrides Sub Initialize(ByVal initializer As Object)

End Sub

Public Overrides Function ChainStream(ByVal stream As Stream) As Stream
originalStream = New MemoryStream
ChainStream = internalStream
End Function

Public Overrides Sub ProcessMessage(ByVal message As SoapMessage)
Select Case message.Stage
Case SoapMessageStage.AfterSerialize
internalStream.Position = 0
Dim xslt As XslTransform = New XslTransform
xslt.Load("..\identity.xslt")
Dim xd As XmlDocument = New XmlDocument
xd.Load(internalStream)

Dim ms As MemoryStream = New MemoryStream
xslt.Transform(xd, Nothing, ms, Nothing)

ms.Position = 0
Dim sr As StreamReader = New StreamReader(ms)

Dim f As New DisplayMessage
f.txtMessage.Text = sr.ReadToEnd
f.Show()

internalStream.Position = 0
CopyStream(originalStream, internalStream)
internalStream.Position = 0

Case SoapMessageStage.BeforeDeserialize
CopyStream(originalStream, internalStream)
internalStream.Position = 0

Dim xslt As XslTransform = New XslTransform
xslt.Load("..\identity.xslt")

Dim xd As XmlDocument = New XmlDocument
xd.Load(internalStream)

Dim ms As MemoryStream = New MemoryStream
xslt.Transform(xd, Nothing, ms, Nothing)

ms.Position = 0
Dim sr As StreamReader = New StreamReader(ms)

Dim f As New DisplayMessage
f.txtMessage.Text = sr.ReadToEnd
f.Show()
internalStream.Position = 0

End Select
End Sub

Private Sub CopyStream(ByVal fromStream As Stream, ByVal toStream As
Stream)
Try
Dim sr As New StreamReader(fromStream)
Dim sw As New StreamWriter(toStream)
sw.WriteLine(sr.ReadToEnd)
sw.Flush()
Catch ex As Exception

End Try
End Sub
End Class

Imports System.Web.Services
Imports System.Web.Services.Protocols

<AttributeUsage(AttributeTargets.Method)> _
Public Class SoapDisplayExtensionAttribute
Inherits SoapExtensionAttribute

Private m_Priority As Integer = 1
Public Overrides ReadOnly Property ExtensionType() As System.Type
Get
ExtensionType = GetType(SoapDisplayExtension)
End Get
End Property

Public Overrides Property Priority() As Integer
Get
Priority = m_Priority
End Get
Set(ByVal Value As Integer)
m_Priority = Value
End Set
End Property
End Class
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Found my problem woo hoo!

I was returning a Null stream from the ChainStream function. I had the code
goofed up in there. Should have been this:

originalStream = Stream
internalStream = new MemoryStream()
ChainStream = internalStream

"David C. allen" wrote:
I have created a simple Client-side SOAP Extension for a webclass that I
have. When I apply the extension attribute to the the calling function in the
proxy class I get an error 'Value cannot be null'. When the extension
attribute is not applied it runs fine. The wierd thing is that it does not
appear to be an error within the SOAP extension because I break-pointed it
and when the proxy function gets called the SOAP extension runs fine. After
the end of the subroutine in the SOAP extension it returns back to run the
proxy function and gets an error on the actual call to the webservice. Here
is the function call in the proxy:

'<remarks/>
<SoapDisplayExtension(), _
System.Web.Services.Protocols.SoapDocumentMethodAt tribute( _
"http://tempuri.org/BugTracker2/Service1/GetBug" _
, RequestNamespace:="http://tempuri.org/BugTracker2/Service1" _
, ResponseNamespace:="http://tempuri.org/BugTracker2/Service1" _
, Use:=System.Web.Services.Description.SoapBindingUs e.Literal _
,
ParameterStyle:=System.Web.Services.Protocols.Soap ParameterStyle.Wrapped)> _
Public Function GetBug(ByVal BugID As Integer) As Bug
Dim results() As Object
results = Me.Invoke("GetBug", New Object() {BugID})
Return CType(results(0), Bug)
End Function

The error occurs on this line: results = Me.Invoke("GetBug", New
Object() {BugID})

The error is: Unhandled exception of type 'System.ArgumentNullException'
occured in mscorlib.dll. Addition infomation: Value cannot be null

If I remove the attribute: SoapDisplayExtension(), then this line runs fine.

Any ideas?

Thanks!!

PS here is the SOAP extension code and attribute code:

Imports System.IO
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml
Imports System.Xml.Xsl

Public Class SoapDisplayExtension
Inherits SoapExtension

Private originalStream As Stream
Private internalStream As Stream

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

End Function

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

End Function

Public Overrides Sub Initialize(ByVal initializer As Object)

End Sub

Public Overrides Function ChainStream(ByVal stream As Stream) As Stream
originalStream = New MemoryStream
ChainStream = internalStream
End Function

Public Overrides Sub ProcessMessage(ByVal message As SoapMessage)
Select Case message.Stage
Case SoapMessageStage.AfterSerialize
internalStream.Position = 0
Dim xslt As XslTransform = New XslTransform
xslt.Load("..\identity.xslt")
Dim xd As XmlDocument = New XmlDocument
xd.Load(internalStream)

Dim ms As MemoryStream = New MemoryStream
xslt.Transform(xd, Nothing, ms, Nothing)

ms.Position = 0
Dim sr As StreamReader = New StreamReader(ms)

Dim f As New DisplayMessage
f.txtMessage.Text = sr.ReadToEnd
f.Show()

internalStream.Position = 0
CopyStream(originalStream, internalStream)
internalStream.Position = 0

Case SoapMessageStage.BeforeDeserialize
CopyStream(originalStream, internalStream)
internalStream.Position = 0

Dim xslt As XslTransform = New XslTransform
xslt.Load("..\identity.xslt")

Dim xd As XmlDocument = New XmlDocument
xd.Load(internalStream)

Dim ms As MemoryStream = New MemoryStream
xslt.Transform(xd, Nothing, ms, Nothing)

ms.Position = 0
Dim sr As StreamReader = New StreamReader(ms)

Dim f As New DisplayMessage
f.txtMessage.Text = sr.ReadToEnd
f.Show()
internalStream.Position = 0

End Select
End Sub

Private Sub CopyStream(ByVal fromStream As Stream, ByVal toStream As
Stream)
Try
Dim sr As New StreamReader(fromStream)
Dim sw As New StreamWriter(toStream)
sw.WriteLine(sr.ReadToEnd)
sw.Flush()
Catch ex As Exception

End Try
End Sub
End Class

Imports System.Web.Services
Imports System.Web.Services.Protocols

<AttributeUsage(AttributeTargets.Method)> _
Public Class SoapDisplayExtensionAttribute
Inherits SoapExtensionAttribute

Private m_Priority As Integer = 1
Public Overrides ReadOnly Property ExtensionType() As System.Type
Get
ExtensionType = GetType(SoapDisplayExtension)
End Get
End Property

Public Overrides Property Priority() As Integer
Get
Priority = m_Priority
End Get
Set(ByVal Value As Integer)
m_Priority = Value
End Set
End Property
End Class

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.