You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by mo...@citadon.com on 2001/08/26 04:09:27 UTC

Sending xml data as a string using SOAP

Hi,

	I have a method in my soap service which returns a large XML data as
a string value. (the data is greater than 1 MB in size) Now, the method
returns the string but the client never gets the data. (May be it will get
the data after a very long time, which is not acceptable). I assume that the
client (Apache SOAP client libs) is parsing all the XML data which is
returned, causing the delay. A non-xml string of the same size gets to the
client in a short time. Is there any solution for this problem ? I have
tried wrapping data in CDATA tags. That doesn't work, I don't know for what
reason. I read that using xml-literal encoding style would solve the problem
and tried to set the encoding style in my client code. When I do that, the
server throws an exception  - " Fault Code   = SOAP-ENV:Server Fault String
= java.lang.IllegalArgumentException: I only know how to serialize an
'org.w3c.dom.Element'.". If anybody knows how to solve this issue, please
respond.

thanks,
Mohan



Re: Sending xml data as a string using SOAP

Posted by William Brogden <wb...@bga.com>.

mohank@citadon.com wrote:
> 
> Hi,
> 
>         I have a method in my soap service which returns a large XML data as
> a string value. (the data is greater than 1 MB in size) Now, the method
> returns the string but the client never gets the data. (May be it will get
> the data after a very long time, which is not acceptable). I assume that the
> client (Apache SOAP client libs) is parsing all the XML data which is
> returned, causing the delay. A non-xml string of the same size gets to the
> client in a short time. Is there any solution for this problem ? I have
> tried wrapping data in CDATA tags. That doesn't work, I don't know for what
> reason. I read that using xml-literal encoding style would solve the problem
> and tried to set the encoding style in my client code. When I do that, the
> server throws an exception  - " Fault Code   = SOAP-ENV:Server Fault String
> = java.lang.IllegalArgumentException: I only know how to serialize an
> 'org.w3c.dom.Element'.". If anybody knows how to solve this issue, please
> respond.
> 
> thanks,
> Mohan

Sounds like the server doesn't know that your input parameter is 
not the same type as the return type. I got the same kind of message
due to that. Here is the envelope I ended up sending  -
 note that the param tag, which holds a String has its own
 encodingStyle:

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:getByCode xmlns:ns1="urn:Publications"
SOAP-ENV:encodingStyle="http://xml.apache.org/xml-soap/literalxml">
<param xsi:type="xsd:string"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">1-5888-0139-X</param>
</ns1:getByCode>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

====== here is the code that generated that envelope
 private Element getElement( String method, String param ) throws
Exception {
    URL url = new URL( protocol, pubsHost, port, pubsURL );
    Call call = new Call();
    //
    call.setTargetObjectURI("urn:Publications");
    call.setMethodName(method);
    call.setEncodingStyleURI(Constants.NS_URI_LITERAL_XML);
    if( param != null ){
      Vector params = new Vector();
      params.addElement(new Parameter("param", String.class,
                           param, Constants.NS_URI_SOAP_ENC ));
      call.setParams(params);
    }
    // Invoke the call.
    Response resp;
    try {
      resp = call.invoke(url, "");
    } catch (SOAPException e) {
      System.err.println("Caught SOAPException (" +
                         e.getFaultCode() + "): " +
                         e.getMessage());
      return null ;
    }
    if (!resp.generatedFault()) {
      Parameter ret = resp.getReturnValue();
      Element bookEl = (Element)ret.getValue();
      return bookEl ;
    }
    // if here, response contains a fault
    printFault( resp, System.err );
    return null ;
  }



-- 
WBB - wbrogden@lanw.com
Java Cert mock exams http://www.lanw.com/java/javacert/
Author of Java Developer's Guide to Servlets and JSP 
ISBN 0-7821-2809-2

Re: Sending xml data as a string using SOAP

Posted by William Brogden <wb...@bga.com>.

mohank@citadon.com wrote:
> 
> Hi,
> 
>         I have a method in my soap service which returns a large XML data as
> a string value. (the data is greater than 1 MB in size) Now, the method
> returns the string but the client never gets the data. (May be it will get
> the data after a very long time, which is not acceptable). I assume that the
> client (Apache SOAP client libs) is parsing all the XML data which is
> returned, causing the delay. A non-xml string of the same size gets to the
> client in a short time. Is there any solution for this problem ? I have
> tried wrapping data in CDATA tags. That doesn't work, I don't know for what
> reason. I read that using xml-literal encoding style would solve the problem
> and tried to set the encoding style in my client code. When I do that, the
> server throws an exception  - " Fault Code   = SOAP-ENV:Server Fault String
> = java.lang.IllegalArgumentException: I only know how to serialize an
> 'org.w3c.dom.Element'.". If anybody knows how to solve this issue, please
> respond.
> 
> thanks,
> Mohan

Sounds like the server doesn't know that your input parameter is 
not the same type as the return type. I got the same kind of message
due to that. Here is the envelope I ended up sending  -
 note that the param tag, which holds a String has its own
 encodingStyle:

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:getByCode xmlns:ns1="urn:Publications"
SOAP-ENV:encodingStyle="http://xml.apache.org/xml-soap/literalxml">
<param xsi:type="xsd:string"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">1-5888-0139-X</param>
</ns1:getByCode>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

====== here is the code that generated that envelope
 private Element getElement( String method, String param ) throws
Exception {
    URL url = new URL( protocol, pubsHost, port, pubsURL );
    Call call = new Call();
    //
    call.setTargetObjectURI("urn:Publications");
    call.setMethodName(method);
    call.setEncodingStyleURI(Constants.NS_URI_LITERAL_XML);
    if( param != null ){
      Vector params = new Vector();
      params.addElement(new Parameter("param", String.class,
                           param, Constants.NS_URI_SOAP_ENC ));
      call.setParams(params);
    }
    // Invoke the call.
    Response resp;
    try {
      resp = call.invoke(url, "");
    } catch (SOAPException e) {
      System.err.println("Caught SOAPException (" +
                         e.getFaultCode() + "): " +
                         e.getMessage());
      return null ;
    }
    if (!resp.generatedFault()) {
      Parameter ret = resp.getReturnValue();
      Element bookEl = (Element)ret.getValue();
      return bookEl ;
    }
    // if here, response contains a fault
    printFault( resp, System.err );
    return null ;
  }



-- 
WBB - wbrogden@lanw.com
Java Cert mock exams http://www.lanw.com/java/javacert/
Author of Java Developer's Guide to Servlets and JSP 
ISBN 0-7821-2809-2