Webservice without IIS and ASP.NET: problem with SoapFormatter...
Today I played a little bit with remoting over an HTTP channel using the SOAP protocol. I created a factory class, comparable to a webservice class (asmx) when using normal webservices in ASP.NET.
Public Class Engine
Inherits MarshalByRefObject
Public Sub New()
MyBase.New()
End Sub
Public Function TestMe() As String
Return "Test"
End Function
Public Function GetCustomer() As Customer
Dim c As New Customer
c.Name = "Jan"
c.Tel = "111"
Return c
End Function
End Class
I published my Engine class using the following code:
Dim channel As New Http.HttpChannel(8080)
ChannelServices.RegisterChannel(channel)
RemotingConfiguration.ApplicationName = "myTest"
RemotingConfiguration.RegisterWellKnownServiceType(GetType(Engine), "test.soap", WellKnownObjectMode.SingleCall)
Everything worked fine, I could ask the wsdl of the webservice and call the TestMe method of the Engine class from a WindowsApp through a WebReference. The problems started when I wanted to test the GetCustomer method, which returns a complex type that is defined on the server like this:
Public Class Customer
Private _name As String
Private _tel As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal Value As String)
_name = Value
End Set
End Property
Public Property Tel() As String
Get
Return _tel
End Get
Set(ByVal Value As String)
_tel = Value
End Set
End Property
End Class
The generated proxy class in the client project, has 2 members named "_name" and "_tel"! So, unlike a normal webservice, all the Fields of the Customer class will be serialized, instead of the Properties... I discovered that this behaviour is the result of the fact that Remoting uses the SoapFormatter class to serialize to XML. That SoapFormatter class serializes all the Fields, but not the Properties of a class. A normal ASP.NET Webservice uses the XMLSerializer class to serialize to XML, which serializes all the Properties, and not the fields, to XML.
Does anyone know how to change this behaviour? What I want to do, is to "emulate" webservices, without using IIS, so Remoting has to be used. Any hints or tips would be greatly appriciated!