473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Passing complex types to/from an Axis-based Web service?

Hello.

I'm trying to exchange data between a webservice based on Apache Axis
and a client written in C#, and so far it has been working with few
problems (none that I couldn't solve myself with a bit of web
research). However, now I've tried passing complex data types between
the two, and could not get that to work.

What I did was to declare my data type on the Axis/Java side as an
Object implementing java.io.Serializable, and when I use that as a
parameter/return type in one of my web service methods, Axis includes
an appropriate type declaration in the WSDL (I'm using the code-first
approach, writing the service code as needed, and letting Axis generate
the WSDL) and when I add the web reference to the .NET project, the
Object is recreated perfectly from that. Looking good - so far...
*However* when I actually try to pass such an object to or from a
method, .NET and/or Java (depending on which way I try to pass it)
throws an exception claiming that there's no suitable (de)serializer
for the object.

Now, this may seem naive, but I thought that the default serialization
would be enough to handle a simple object containing nothing but a
handful of fields of primitive data types... So, am I missing anything?
Doing something fundamentally wrong? Or do I seriously have to
explicitly create (de)serialization code for every non-primitive data
type I'd like to pass?

Thanks in advance for any suggestions.

Nov 17 '06 #1
3 7287
<an**********@meta-level.dewrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hello.

I'm trying to exchange data between a webservice based on Apache Axis
and a client written in C#, and so far it has been working with few
problems (none that I couldn't solve myself with a bit of web
research). However, now I've tried passing complex data types between
the two, and could not get that to work.

What I did was to declare my data type on the Axis/Java side as an
Object implementing java.io.Serializable, and when I use that as a
parameter/return type in one of my web service methods, Axis includes
an appropriate type declaration in the WSDL (I'm using the code-first
approach, writing the service code as needed, and letting Axis generate
the WSDL) and when I add the web reference to the .NET project, the
Object is recreated perfectly from that. Looking good - so far...
*However* when I actually try to pass such an object to or from a
method, .NET and/or Java (depending on which way I try to pass it)
throws an exception claiming that there's no suitable (de)serializer
for the object.

Now, this may seem naive, but I thought that the default serialization
would be enough to handle a simple object containing nothing but a
handful of fields of primitive data types... So, am I missing anything?
Doing something fundamentally wrong? Or do I seriously have to
explicitly create (de)serialization code for every non-primitive data
type I'd like to pass?

Thanks in advance for any suggestions.
Check carefully and make sure the XML namespaces are the same on both sides.

Also, for the future, be aware that there are some XML Schema constructs
that Axis (or JAXB, I guess) doesn't seem to like. Even something like a
maxOccurs on an xsd:sequence element cause it to choke.

John
Nov 17 '06 #2
John Saunders schrieb:
Check carefully and make sure the XML namespaces are the same on both sides.

Also, for the future, be aware that there are some XML Schema constructs
that Axis (or JAXB, I guess) doesn't seem to like. Even something like a
maxOccurs on an xsd:sequence element cause it to choke.
First of all, thanks for your reply, but I'm not exactly sure what to
make of it (have patience with me, please, this whole web service
business is all new for me). There are so many different namespaces
involved, I have no idea which have to match which others...

Now, I *think* I made some progress. Realizing that maybe it was a bit
much to ask for to expect Axis to be able to serialize arbitrary
objects, I turned the object in question into a java bean, and added a
<beanMappingentry to the deployment descriptor. Now, at least, the
service itself actually manages to respond to my request instead of
throwing an exception; however, .NET still fails to convert the
response result back into a usable object in the generated stub code
for the web reference:

public ComplexDataObject ComplexOut() {
object[] results = this.Invoke("ComplexOut", new object[0]);
return ((ComplexDataObject)(results[0]));
}

Apparently, results[0] is not a single object ready for type conversion
into ComplexDataObject, it is rather an array containing the XML
attributes and elements of the response (the latter being the
individual fields of the passed object).

Obviously, I am still doing something wrong. If anyone has any idea as
to what that might be, I'd love to hear it. If more info is required,
I'd gladly post some snippets from the code/wsdd/wsdl files involved, I
just didn't want to spam this group with it without knowing if that
would even be helpful...

Nov 17 '06 #3
<an**********@meta-level.dewrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
John Saunders schrieb:
>Check carefully and make sure the XML namespaces are the same on both
sides.

Also, for the future, be aware that there are some XML Schema constructs
that Axis (or JAXB, I guess) doesn't seem to like. Even something like a
maxOccurs on an xsd:sequence element cause it to choke.

First of all, thanks for your reply, but I'm not exactly sure what to
make of it (have patience with me, please, this whole web service
business is all new for me). There are so many different namespaces
involved, I have no idea which have to match which others...

Now, I *think* I made some progress. Realizing that maybe it was a bit
much to ask for to expect Axis to be able to serialize arbitrary
objects
....

You actually have hit the nail on the head.

Web Services isn't about communicating objects. It's about communicating
XML. We send and receive XML, which matches an XML schema, referenced by a
WSDL file which is also XML. Think XML.

We like to program to objects, of course, and we can often do so without
ever thinking about the XML in the middle. But you really have no reason to
believe that the Java object type system on one side can translate arbitrary
Java objects to XML, send them to the .NET CLR object type system on the
other side and have it deserialize into an "equivalent" arbitrary .NET CLR
type. Similarly, there will be XML structures that translate into objects in
one type system but will not translate into objects in the other type
system.

So, what to do? Take the data you want to send, and create an XML schema
which describes it at a semantic level. Leave out any high-level OO or
relational concepts and just describe the data. For instance, in
transmitting a DataSet, just describe the rows and columns and ignore
anything having to do with indexes, keys or relations. For OO classes,
ignore any of the methods and concentrate on the data. Simplify the data
types. For instance, you don't need to transmit a Java Map object or .NET
Hashtable; you need to transmit an array of key/value pairs.

Given that XSD schema, run it through XSD.EXE on .Net and the equivalent on
Java. Keep playing with the schema until you can generate correct classes on
both platforms.

What you'll wind up with is what's known as a Data Transfer Object (as
opposed to a Business Object). Define your operations in terms of this DTO.
It means you'll have to pack or unpack your complex objects or DataSets into
and out of the DTO, which is tedious to code. But it means that you will be
communicating at all levels in XML and in OO structures which map to the
XML.

Sorry for the mini-lecture; I hope that helps.

John
Nov 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
0
by: olafmol | last post by:
Hello, i have a problem using a .NET WSDL Webservice from PHP. Using both the NuSOAP lib for PHP4, and the build-in SOAP lib for PHP5 it seems that the SOAP client cannot pass a variable amount...
17
by: Chris Travers | last post by:
Hi all; I just made an interesting discovery. Not sure if it is a good thing or not, and using it certainly breakes first normal form.... Not even sure if it really works. However, as I am...
6
by: Arghknork | last post by:
Heres a dumb one. I know you can't actually pass reference types by value in C#, but I want to pass an object into a method and allow that method to manipulate a copy of that object, such that the...
3
by: Germic | last post by:
Hi, I want to create an Hashtable in C# and pass an pointer to the hashtable to a C code. Later, the C code could reference the hashtable by passing the pointer to the hashtable as a ref...
3
by: aaa | last post by:
I am having trouble getting a complex data type to get passed to a non-COM dll's function by ref and return back data from that object. Simple data types work fine but when I try the complex data...
0
by: Dan A | last post by:
I have a SOAP written in Java, and being served by Apache Axis - using the wrapped mode. I then used VS 2003 to generate C# client stubs. I have many complex types that are returned - and these...
11
by: cps | last post by:
Hi, I'm a C programmer taking my first steps into the world of C++. I'm currently developing a C++ 3D graphics application using GLUT (OpenGL Utility Toolkit written in C) for the GUI...
17
by: Julian V. Noble | last post by:
Dear C Mavens, I am writing a Computing Prescription for CiSE on complex arithmetic. I would like to be sure that I do not include any gaffes about C99--especially about what is in the header...
11
by: jacob navia | last post by:
hi I am trying to use the complex data type. Consider this code, taken from the cclib library: struct complex csqrt(Cpx z) { double r; r=sqrt(z.re*z.re+z.im*z.im);...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.