WebService interfaces and Serialization

A

ArunDhaJ

Hi,
I'm using WebServices and Serializations in my project. In which I
need a few clarification.

I wanted to know how to perform serialization/de-serialization using
interface classes?

I'll brief my scenario;

The following is a webservice interface

MyClassA MyMethodA(MyClassB classB);
In the above interface, i use two classes MyClassA and MyClassB, they
are defined in WSDL.

public MyClassA
{
public int memberAA;
public int memberAB;
}

public MyClassB
{
public int memberBA;
public int memberBB;
}

When building the WebService consumer the classes are even created in
my client side using wsdl.exe utility. And I'm consuming the
webservice without any hassle and my life's good.

My trouble starts here;
Say, I have yet another interface

string GetMyClassA();

the responded string is the serialized from of MyClassA class. Still,
I would not have faced the problem if the xml format is of form:
<MyClassA memberAA="" memberAB="" />

Because, if the xml is of the above format, I would have used the
MyClassA type to deserialize the xml to MyClassA class. But the xml is
some thing as (contracted form of long names):

<a mAA="" mAB="" />

since the elements and attributes name are contracted form, I'm forced
to create yet another class with my own custom XmlAttributes set as

[XmlRoot(ElementName = "a")]
public ClientMyClassA
{
[XmlAttribute(AttributeName = "mAA")]
public int memberAA;
[XmlAttribute(AttributeName = "mAB")]
public int memberAB;
}

This makes my life so complex that, when ever there is a change in xml
format or interfaces, i need to search for this class and update it
accordingly.....

So, I wanted to know if there are any possibilities to combine the
webservice interfaces classes with the XmlAttributes set to it.

I'm pretty new to WebServices, so I'm struggling to search a solution
in internet. Any help would be much appreciated.

Regards
ArunDhaJ
 
A

Asaf Shelly

Hi,

What you are describing sounds more like C\++ than C#.

Try using:

class baseClass
{
int Integer1;
int Integer2;
}

class someClass: baseClass
{
public FirstMember
{
get { return( Interger1 ); }
}
}

Asaf
 
F

Family Tree Mike

Hi,
I'm using WebServices and Serializations in my project. In which I
need a few clarification.

I wanted to know how to perform serialization/de-serialization using
interface classes?

I'll brief my scenario;

The following is a webservice interface

MyClassA MyMethodA(MyClassB classB);
In the above interface, i use two classes MyClassA and MyClassB, they
are defined in WSDL.

public MyClassA
{
public int memberAA;
public int memberAB;
}

public MyClassB
{
public int memberBA;
public int memberBB;
}

When building the WebService consumer the classes are even created in
my client side using wsdl.exe utility. And I'm consuming the
webservice without any hassle and my life's good.

My trouble starts here;
Say, I have yet another interface

string GetMyClassA();

the responded string is the serialized from of MyClassA class. Still,
I would not have faced the problem if the xml format is of form:
<MyClassA memberAA="" memberAB="" />

Because, if the xml is of the above format, I would have used the
MyClassA type to deserialize the xml to MyClassA class. But the xml is
some thing as (contracted form of long names):

<a mAA="" mAB="" />

since the elements and attributes name are contracted form, I'm forced
to create yet another class with my own custom XmlAttributes set as

[XmlRoot(ElementName = "a")]
public ClientMyClassA
{
[XmlAttribute(AttributeName = "mAA")]
public int memberAA;
[XmlAttribute(AttributeName = "mAB")]
public int memberAB;
}

This makes my life so complex that, when ever there is a change in xml
format or interfaces, i need to search for this class and update it
accordingly.....

So, I wanted to know if there are any possibilities to combine the
webservice interfaces classes with the XmlAttributes set to it.

I'm pretty new to WebServices, so I'm struggling to search a solution
in internet. Any help would be much appreciated.

Regards
ArunDhaJ

Your question is a little difficult to follow, but, it sounds like you
would be better served to have a shared (client & server) dll that
contains the definition of MyClassA. This lets you deserialize the
class on both ends. If the dll/serialization change, then you update
the shared dll.
 
A

Arne Vajhøj

Hi,
I'm using WebServices and Serializations in my project. In which I
need a few clarification.

I wanted to know how to perform serialization/de-serialization using
interface classes?

I'll brief my scenario;

The following is a webservice interface

MyClassA MyMethodA(MyClassB classB);
In the above interface, i use two classes MyClassA and MyClassB, they
are defined in WSDL.

public MyClassA
{
public int memberAA;
public int memberAB;
}

public MyClassB
{
public int memberBA;
public int memberBB;
}

When building the WebService consumer the classes are even created in
my client side using wsdl.exe utility. And I'm consuming the
webservice without any hassle and my life's good.

My trouble starts here;
Say, I have yet another interface

string GetMyClassA();

the responded string is the serialized from of MyClassA class. Still,
I would not have faced the problem if the xml format is of form:
<MyClassA memberAA="" memberAB="" />

Because, if the xml is of the above format, I would have used the
MyClassA type to deserialize the xml to MyClassA class. But the xml is
some thing as (contracted form of long names):

<a mAA="" mAB="" />

since the elements and attributes name are contracted form, I'm forced
to create yet another class with my own custom XmlAttributes set as

[XmlRoot(ElementName = "a")]
public ClientMyClassA
{
[XmlAttribute(AttributeName = "mAA")]
public int memberAA;
[XmlAttribute(AttributeName = "mAB")]
public int memberAB;
}

This makes my life so complex that, when ever there is a change in xml
format or interfaces, i need to search for this class and update it
accordingly.....

So, I wanted to know if there are any possibilities to combine the
webservice interfaces classes with the XmlAttributes set to it.

I'm pretty new to WebServices, so I'm struggling to search a solution
in internet. Any help would be much appreciated.

Your question is a little difficult to follow, but, it sounds like you
would be better served to have a shared (client & server) dll that
contains the definition of MyClassA. This lets you deserialize the class
on both ends. If the dll/serialization change, then you update the
shared dll.

If the requirements is that client and server has the same DLL, then
I am skeptical about the choice of SOAP as protocol.

The benefit of SOAP is to decouple client and server. If they are not
decoupled, then SOAP is not really providing any value.

Arne
 
P

Peter Duniho

Arne said:
If the requirements is that client and server has the same DLL, then
I am skeptical about the choice of SOAP as protocol.

The benefit of SOAP is to decouple client and server. If they are not
decoupled, then SOAP is not really providing any value.

Please elaborate. In .NET, serialization usually means
serializing/deserializing a specific type. The client code may be a
different .exe, but the type would still come from the same assembly.

Are you suggesting that it's common in .NET to use SOAP to serialize
from one type, and then to deserialize into a completely different (but
obviously compatible) type?

Of course, there is the little issue that the OP never said anything
about using SOAP, nor Mike in his reply (is SOAP implied by the specific
format the OP mentions, as vague as his description is?). But I'm still
curious about the general issue.

Pete
 
A

Arne Vajhøj

Please elaborate. In .NET, serialization usually means
serializing/deserializing a specific type. The client code may be a
different .exe, but the type would still come from the same assembly.

Are you suggesting that it's common in .NET to use SOAP to serialize
from one type, and then to deserialize into a completely different (but
obviously compatible) type?

Of course, there is the little issue that the OP never said anything
about using SOAP, nor Mike in his reply (is SOAP implied by the specific
format the OP mentions, as vague as his description is?). But I'm still
curious about the general issue.

The point in SOAP is to completely decouple the client and the
server.

The server happen to be written in .NET.

The client could be written in .NET, Java, PHP, Python, Perl etc..

If it is a requirement to get the .NET client to work (or at least
work well) that it has the same DLL with data classes as the server,
then the Java and P* people will have a really big problem.

So yes - the client should have a different implementation of
the data classes.

If it is only .NET clients that will ever be used, then the DLL
can be shared, but then it would be very beneficial performance wise
to go for a binary serialization instead of SOAP.

SOAP is portable, but it is not fast.

WCF makes is very easy to switch between SOAP and binary as
transport format.

That requires .NET 3.0 or newer though !

Arne

PS: The original post mentions web service, XML format and
use of the old WSDL utility, which can only mean SOAP.
 
F

Family Tree Mike

Hi,
I'm using WebServices and Serializations in my project. In which I
need a few clarification.

I wanted to know how to perform serialization/de-serialization using
interface classes?

I'll brief my scenario;

The following is a webservice interface

MyClassA MyMethodA(MyClassB classB);
In the above interface, i use two classes MyClassA and MyClassB, they
are defined in WSDL.

public MyClassA
{
public int memberAA;
public int memberAB;
}

public MyClassB
{
public int memberBA;
public int memberBB;
}

When building the WebService consumer the classes are even created in
my client side using wsdl.exe utility. And I'm consuming the
webservice without any hassle and my life's good.

My trouble starts here;
Say, I have yet another interface

string GetMyClassA();

the responded string is the serialized from of MyClassA class. Still,
I would not have faced the problem if the xml format is of form:
<MyClassA memberAA="" memberAB="" />

Because, if the xml is of the above format, I would have used the
MyClassA type to deserialize the xml to MyClassA class. But the xml is
some thing as (contracted form of long names):

<a mAA="" mAB="" />

since the elements and attributes name are contracted form, I'm forced
to create yet another class with my own custom XmlAttributes set as

[XmlRoot(ElementName = "a")]
public ClientMyClassA
{
[XmlAttribute(AttributeName = "mAA")]
public int memberAA;
[XmlAttribute(AttributeName = "mAB")]
public int memberAB;
}

This makes my life so complex that, when ever there is a change in xml
format or interfaces, i need to search for this class and update it
accordingly.....

So, I wanted to know if there are any possibilities to combine the
webservice interfaces classes with the XmlAttributes set to it.

I'm pretty new to WebServices, so I'm struggling to search a solution
in internet. Any help would be much appreciated.

Your question is a little difficult to follow, but, it sounds like you
would be better served to have a shared (client & server) dll that
contains the definition of MyClassA. This lets you deserialize the class
on both ends. If the dll/serialization change, then you update the
shared dll.

If the requirements is that client and server has the same DLL, then
I am skeptical about the choice of SOAP as protocol.

The benefit of SOAP is to decouple client and server. If they are not
decoupled, then SOAP is not really providing any value.

Arne

In general your comments make sense, but the OP included the following:

// Begin quote
This makes my life so complex that, when ever there is a change in xml
format or interfaces, i need to search for this class and update it
accordingly.....
// End quote

So I took this that they are writing both pieces. Because of this, I
think the shared dll is appropriate to suggest.
 
A

ArunDhaJ

On 1/4/2010 5:09 AM, ArunDhaJ wrote:
Hi,
I'm using WebServices and Serializations in my project. In which I
need a few clarification.
I wanted to know how to perform serialization/de-serialization using
interface classes?
I'll brief my scenario;
The following is a webservice interface
MyClassA MyMethodA(MyClassB classB);
In the above interface, i use two classes MyClassA and MyClassB, they
are defined in WSDL.
public MyClassA
{
public int memberAA;
public int memberAB;
}
public MyClassB
{
public int memberBA;
public int memberBB;
}
When building the WebService consumer the classes are even created in
my client side using wsdl.exe utility. And I'm consuming the
webservice without any hassle and my life's good.
My trouble starts here;
Say, I have yet another interface
string GetMyClassA();
the responded string is the serialized from of MyClassA class. Still,
I would not have faced the problem if the xml format is of form:
<MyClassA memberAA="" memberAB="" />
Because, if the xml is of the above format, I would have used the
MyClassA type to deserialize the xml to MyClassA class. But the xml is
some thing as (contracted form of long names):
<a mAA="" mAB="" />
since the elements and attributes name are contracted form, I'm forced
to create yet another class with my own custom XmlAttributes set as
[XmlRoot(ElementName = "a")]
public ClientMyClassA
{
[XmlAttribute(AttributeName = "mAA")]
public int memberAA;
[XmlAttribute(AttributeName = "mAB")]
public int memberAB;
}
This makes my life so complex that, when ever there is a change in xml
format or interfaces, i need to search for this class and update it
accordingly.....
So, I wanted to know if there are any possibilities to combine the
webservice interfaces classes with the XmlAttributes set to it.
I'm pretty new to WebServices, so I'm struggling to search a solution
in internet. Any help would be much appreciated.
Your question is a little difficult to follow, but, it sounds like you
would be better served to have a shared (client & server) dll that
contains the definition of MyClassA. This lets you deserialize the class
on both ends. If the dll/serialization change, then you update the
shared dll.
If the requirements is that client and server has the same DLL, then
I am skeptical about the choice of SOAP as protocol.
The benefit of SOAP is to decouple client and server. If they are not
decoupled, then SOAP is not really providing any value.

In general your comments make sense, but the OP included the following:

// Begin quote
This makes my life so complex that, when ever there is a change in xml
format or interfaces, i need to search for this class and update it
accordingly.....
// End quote

So I took this that they are writing both pieces.  Because of this, I
think the shared dll is appropriate to suggest.

I agree that the SOAP is for decoupling the client and server. Even in
our case, webservice is a Java based webservice and webservice
consumer is a .Net application. So sharing of common Dll between
client and server is not possible in this case.

May be I'll bit elaborate my problem, of course this is not stopping
my work, but still wanted to improve my application code.
WSDL is already defined. I'm using this WSDL to auto generate the
client side endpoint classes and interfaces using wsdl.exe utility.
While doing so, class declaration for MyClassA and MyClassB would be
generated in that file.
In case, as explained above, if there is an interface which responds
an xml string of previously defined contracted format. I require to
declare the classes MyClassA and MyClassB again with Xml serialization
attributes.

So, I end up with MyClassA and MyClassB declaration twice in the
client-side. My question is to identify how to eliminate this
duplication.

That is why I wanted to know whether there is any possibility of
specifying xml serialization attribute in the classes auto generated
by wsdl.exe utility?

One possibility is to manually add the xml serialization attributes in
the auto generated classes, but when I use wsdl.exe again it
overwrites those custom added attributes.

Hope you might understand the problem now. Please suggest me a
solution... Thanks...

Regards
ArunDhaJ
 
A

Asaf Shelly

Hi,

Using XML to cast an object from one type to another type is just like using
Marshal.StructureToPtr
If you want to cast then do it using the C# way.

What would you do if there was no XML in the way and you were just calling a
function?

Asaf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top