1

How can one specify a custom object as a parameter for the web-service's method when invoking through SOAP message?

Say I have this code:

SOAPElement operation = body.addChildElement("MyMethod", "", trgNamespace);
SOAPElement value = operation.addChildElement("arg0");
value.addTextNode("i need to send here a custom object not a string")
request.saveChanges();

The addTextNode sends a string whereas I need to send my own object as a parameter for invocation.

azerIO
  • 519
  • 1
  • 9
  • 19

3 Answers3

2

You have to serialize your object to transfer it over the line. Serialization is often done using XML or JSON, see the following link for details: http://en.wikipedia.org/wiki/Serialization

That should get you on the right path.

kroonwijk
  • 8,340
  • 3
  • 31
  • 52
  • I could do it through marshaller of jaxb. Another question is how do I inject it in the soap and where? Say, I do have an XML stored in a StringWriter which represents my object. What is the next step to pass it as a parameter? – azerIO Sep 12 '11 at 21:16
  • Unless I do not understand the complexity of your environment ..., just set the string output of your stringwriter as the value of your text node? Or if you want to include any serialized XML content directly in your SOAP message body, use something like an XMLDocument class to read your XML and set it as your document content. – kroonwijk Sep 12 '11 at 21:22
0

Maybe try higher level and use wsdl-based stubs generator for java? It's Axis wsdl to java

Y.A.P.
  • 528
  • 4
  • 12
  • But why you can't just make it value.addChildElement(SOAPElement element)? In other case [if it need to be a string] you should, as kroonwijk writes, use serialization. – Y.A.P. Sep 12 '11 at 21:22
  • I have a web-service with "MyMethod" method. This method accepts a custom-defined object. How can I invoke this method specifying the custom object on the client side by using only soap messages and no axis/cfx etc. – azerIO Sep 12 '11 at 21:40
0

I could think of another approach

  1. You can send that custom object as a binary data (I assume your object is serialize-able). Then encode that data in say Base64 encoding.
  2. There is similar problem asked earlier. Plz check out this link. This seems most relevant to your problem.
  3. Another link mentioned in the above posting gives nice overview of handling these type of problems in general.
Community
  • 1
  • 1
Santosh
  • 17,667
  • 4
  • 54
  • 79