Hi!. I'm trying to develop a "pure" dynamic client to invoke WS's. The idea
behind this, is that I can't generate any classes to invoke the
web-services. Particularly, I can't use specific classes for return types. I
thought about using org.w3c.dom.Document as return type, but I'm not being
successful. The problem I'have, is that, when I return from service's
invocation, the resultant document only contains the first node of the
response.

I would be very grateful if someone could help me to obtain the whole
document.

Here is my stuff. As you will see, the "conversation" with the service is
well-made, so I think that my problem is when the result is read. I don't
know how to read response by myself, or how, where and what configure to
read it well.

-------------------------------------------------------------------------------------
wsdl: http://www.webservicex.net/geoipservice.asmx?wsdl
-------------------------------------------------------------------------------------
Client code (running inside a servlet hosted in jBoss 4.2.1)

package concrete;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.client.ServiceFactory;
import org.apache.axis.constants.Style;
import org.apache.axis.constants.Use;
import org.apache.axis.encoding.ser.DocumentDeserializerFactory;
import org.apache.axis.encoding.ser.DocumentSerializerFactory;
import org.apache.axis.soap.SOAPConstants;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import actions.IAction;

public class TestParams implements IAction {

    @Override
    public void execute(HttpServletRequest req, HttpServletResponse resp) {
        try {
            QName name = new QName("http://www.webservicex.net";,
"GeoIPService");

            Service service = (Service) ServiceFactory
                    .newInstance()
                    .createService(
                            new URL(
                                    "
http://webservicex.net/geoipservice.asmx?wsdl";),
                            name);

            QName port = new QName(name.getNamespaceURI(),
"GeoIPServiceSoap");
            QName oper = new QName(name.getNamespaceURI(), "GetGeoIP");

            Call call = (Call) service.createCall(port, oper);

            call.setTargetEndpointAddress("
http://webservicex.net/geoipservice.asmx";);

            call.setEncodingStyle(null);
            call.setProperty(Call.SOAPACTION_USE_PROPERTY, new
Boolean(true));
            call.setProperty(Call.SOAPACTION_URI_PROPERTY,
                    "http://www.webservicex.net/GetGeoIP";);
            call.setSOAPVersion(SOAPConstants.SOAP11_CONSTANTS);
            call.setOperationUse(Use.LITERAL);
            call.setOperationStyle(Style.WRAPPED_STR);

            call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR,
                    Boolean.FALSE);
            call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS,
                    Boolean.FALSE);

            call.setReturnType(new QName(name.getNamespaceURI(), "GeoIP"));
            call.setReturnClass(Document.class);

            call.registerTypeMapping(Document.class,
                    new QName(name.getNamespaceURI(), "GeoIP"),
                    DocumentSerializerFactory.class,
                    DocumentDeserializerFactory.class,
                    false
                    );


            setRequestHeaders(call);
            setAttachments(call);

            Object[] params = new Object[] { "203.244.123.15" };

            Document doc;

            doc = (Document) call.invoke(params);

            printDocument(doc, resp.getWriter());

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (ServiceException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void printDocument(Document ret, PrintWriter writer) {
        NodeList childNodes = ret.getChildNodes();

        for (int i = 0; i < childNodes.getLength(); i++) {
            printNode(0, childNodes.item(i), writer);
        }
    }

    private void printNode(int level, Node node, PrintWriter writer) {
        String pre = "";

        for (int i = 0; i < level; i++) {
            pre += "\t";
        }

        String strNode = String.format("%s%s = %s", pre, node.getNodeName(),
                node.getNodeValue());

        writer.println(strNode);

        NodeList childNodes = node.getChildNodes();

        for (int i = 0; i < childNodes.getLength(); i++) {
            printNode(level++, childNodes.item(i), writer);
        }

    }

}
-------------------------------------------------------------------------------------
SOAP request being posted (body tabbed for readability)

POST http://webservicex.net:80/geoipservice.asmx HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.4
Host: webservicex.net
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: "http://www.webservicex.net/GetGeoIP";
Content-length: 354

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="
http://schemas.xmlsoap.org/soap/envelope/"; xmlns:xsd="
http://www.w3.org/2001/XMLSchema"; xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance";>
<soapenv:Body>
<GetGeoIP xmlns="http://www.webservicex.net";>
<IPAddress>203.244.123.15</IPAddress>
</GetGeoIP>
</soapenv:Body>
</soapenv:Envelope>
--------------------------------------------------------------------------------------
SOAP response received (body tabbed for readability)

HTTP/1.0 200 OK
Date: Tue, 30 Oct 2007 20:05:44 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-length: 524
X-Cache: MISS from httpproxy
Via: 1.0 httpproxy:3128 (squid)
Proxy-Connection: close

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns:xsd="
http://www.w3.org/2001/XMLSchema";>
<soap:Body>
<GetGeoIPResponse xmlns="http://www.webservicex.net";>
<GetGeoIPResult>
<ReturnCode>1</ReturnCode>
<IP>203.244.123.15</IP>
<ReturnCodeDetails>Record Found</ReturnCodeDetails>
<CountryName>KOREA REPUBLIC OF</CountryName>
<CountryCode>KR</CountryCode>
</GetGeoIPResult>
</GetGeoIPResponse>
</soap:Body>
</soap:Envelope>
---------------------------------------------------------
What printDocument() method shows:

ns1:ReturnCode = null
#text = 1

---------------------------------------------------------

Thanks,
            Ernesto Pin

Reply via email to