Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

 

I have the following web service

 

----------

Imports System.Web.Services

Imports System

Imports System.IO

Imports System.Runtime.Serialization.Formatters

Imports System.Runtime.Serialization.Formatters.Binary

Imports System.Runtime.Serialization.Formatters.Soap

 

<System.Web.Services.WebService

(Namespace := "http://tempuri.org/serv_serial/Service1")> _

Public Class Service1

Inherits System.Web.Services.WebService

 

<Serializable()> Class Employee

Public Name As String

Public Address As String

Public Salary As Double

End Class

 

<WebMethod()> _

Public Function Serialize(ByVal obj As Object) As Stream

Dim fs As FileStream = New _

FileStream("c:\\vbdata.xml", FileMode.OpenOrCreate,

FileAccess.ReadWrite, FileShare.ReadWrite)

Dim sFmt As SoapFormatter = New SoapFormatter

sFmt.Serialize(fs, obj)

Return fs

End Function

<WebMethod()> _

Public Function Deserialize(ByVal s As Stream) As Object

Dim fs As SoapFormatter = New SoapFormatter

s.Position = 0

Return fs.Deserialize(s)

End Function

<WebMethod()> _

Public Function GetEmployeeInfo() As Stream

Dim emp As Employee = New Employee

emp.Name = "Tim"

emp.Address = " First Street, Country "

emp.Salary = 10000.0

Dim s As FileStream = Serialize(emp)

Return s

End Function

 

End Class

 

-----------

 

I call this web service in the following manner

 

Imports System

'Imports System.IO

Imports System.Runtime.Serialization.Formatters

Imports System.Runtime.Serialization.Formatters.Binary

Imports System.Runtime.Serialization.Formatters.Soap

 

Public Class WebForm1

Inherits System.Web.UI.Page

 

 

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

 

Dim x As New service_employee.Service1

 

Dim s As service_employee.Stream = x.GetEmployeeInfo()

 

Dim y As Object = x.Deserialize(s)

 

Response.Write(y.Name & "<BR>")

Response.Write(y.Address & "<BR>")

Response.Write(y.Salary & "<BR>")

 

End Sub

 

End Class

 

------

 

but for some reason, it is blowing up after GetEmployeeInfo is done.

 

Do you know why this is happening?

 

Thank you,

 

Burak

Posted

Hi,

 

In the beginning x.url gets set to

 

"http://localhost/burak/serv_serial/Service1.asmx"

 

In the GetEmployeeInfo code, s gets set to

 

s.Length = 761

s.Name = "c\vbdata.xml"

 

and the type for s is "System.IO.FileStream".

 

It blows up after it comes out of GetEmployeeInfo.

 

Here is what gets returned

 

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: System.IO.FileStream cannot be serialized because it does not have a default public constructor. at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference) at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type) at System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeException(Type type) at System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeException(Object o) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write2_Stream(String n, String ns, Stream o, Boolean isNullable, Boolean needType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write13_GetEmployeeInfoResponse(Object[] p) --- End of inner exception stack trace --- at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle) at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces) at System.Web.Services.Protocols.SoapServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream) at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues) at System.Web.Services.Protocols.WebServiceHandler.Invoke() --- End of inner exception stack trace ---

  • Administrators
Posted (edited)

Ah, basically you can't return a Stream from a web service.

 

Could you not use a single method to open he stream and return the data i.e.

 

 _
Public Function Deserialize() As Object
Dim emp As Employee = New Employee
emp.Name = "Tim"
emp.Address = " First Street, Country "
emp.Salary = 10000.0
Dim s As FileStream = Serialize(emp)

Dim fs As SoapFormatter = New SoapFormatter
s.Position = 0
Return fs.Deserialize(s)
End Function

 

is there any reason the two functions where separate?

Edited by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Actually, I have a .net soap-client that needs to access a websphere soap-server.

 

I read somewhere that we have to

 

"generate the proxy(using wsdl.exe ) classes agains WEBSPHERE web services ".

 

I am new to .net and web services and don't know much about the wsdl.exe tool.

 

Can you tell me how I can generate this proxy class?

 

Thank you,

 

Burak

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...