axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eddie johnston <eddie.johns...@ucd.ie>
Subject what am I doing wrong? (newbie!)
Date Fri, 11 Apr 2003 16:38:51 GMT
Hi there,
 I have two pieces of code - one of them works, the other doesn't, and
what I'm looking for is the second piece to do exactly the same as the
first piece! The code should invoke a simple stockquote service and get
a reply. I'm new to this, so my problem will probably be obvious! Hope
someone can point me in the right direction,

Here's the working piece:



import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

import org.apache.axis.Message;
import org.apache.axis.MessageContext;

import javax.xml.namespace.QName;
import javax.xml.soap.*

public class sample{
    static org.apache.axis.description.OperationDesc [] _operations;

    static {
        _operations = new org.apache.axis.description.OperationDesc[2];
        org.apache.axis.description.OperationDesc oper;
        oper = new org.apache.axis.description.OperationDesc();
        oper.setName("GetQuickQuote");
        oper.addParameter(
            new
javax.xml.namespace.QName("http://nexus6studio.org/Services/",
"Ticker"),
            new
javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"),
            java.lang.String.class,
            org.apache.axis.description.ParameterDesc.IN,
            false, false
        );
        oper.setReturnType(new
javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",
"string"));
        oper.setReturnClass(java.lang.String.class);
        oper.setReturnQName(new
javax.xml.namespace.QName("http://nexus6studio.org/Services/",
"GetQuickQuoteResult"));
        oper.setStyle(org.apache.axis.enum.Style.WRAPPED);
        oper.setUse(org.apache.axis.enum.Use.LITERAL);
        _operations[0] = oper;
    }

    public static void main(String [] args) {
        try {
            java.net.URL endpoint = new
java.net.URL("http://www.nexus6studio.org/Services/StockQoute.asmx");

            Service  service = new Service();
            Call     _call    = (Call) service.createCall();

            _call.setTargetEndpointAddress(endpoint);
            _call.setOperation(_operations[0]);
            _call.setUseSOAPAction(true);
           
_call.setSOAPActionURI("http://nexus6studio.org/Services/GetQuickQuote");
            _call.setEncodingStyle(null);
           
_call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR,
Boolean.FALSE);
           
_call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS,
Boolean.FALSE);
           
_call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
            _call.setOperationName(new
javax.xml.namespace.QName("http://nexus6studio.org/Services/",
"GetQuickQuote"));

            java.lang.Object _resp = _call.invoke(new java.lang.Object[]
{"MSFT"});
            Message m = _call.getResponseMessage();
            SOAPEnvelope en = m.getSOAPEnvelope();
            SOAPBody body = en.getBody();
            System.out.println(body);

            System.out.println("Sent 'MSFT', got '" + _resp + "'");
        }
    }
}


And here's the different approach that doesn't work (note that I may
have the Qnames wrong)

import javax.xml.rpc.*;
import javax.xml.namespace.QName;

public class next{
    private static String endpoint =
"http://www.nexus6studio.org/Services/StockQoute.asmx";
    private static String qnameService =
"http://nexus6studio.org/Services/GetQuickQuote";//
    private static String qnamePort = "GetQuickQuote";//

    private static String BODY_NAMESPACE_VALUE = "";
    private static String ENCODING_STYLE_PROPERTY =
"javax.xml.rpc.encodingstyle.namespace.uri";
    private static String NS_XSD = "http://www.w3.org/2001/XMLSchema";
    private static String URI_ENCODING =
"http://schemas.xmlsoap.org/soap/encoding/";

    public static void main(String args[])throws Exception{
        try{

            ServiceFactory factory = ServiceFactory.newInstance();
            Service service = factory.createService(new
QName(qnameService));
            QName port = new QName(qnamePort);

            Call call = service.createCall(port);
            call.setTargetEndpointAddress(endpoint);

            call.setProperty(Call.SOAPACTION_USE_PROPERTY, new
Boolean(true));
            call.setProperty(Call.SOAPACTION_URI_PROPERTY,"");
            call.setProperty(ENCODING_STYLE_PROPERTY, URI_ENCODING);

            QName QNAME_TYPE_STRING = new QName(NS_XSD,"string");
            call.setReturnType(QNAME_TYPE_STRING);

            call.setOperationName(new QName(BODY_NAMESPACE_VALUE,
"getQuickQuote"));///
            call.addParameter("Ticker", QNAME_TYPE_STRING,
ParameterMode.IN);///
            String[] params = { "MSDN" };///

            String result = (String)call.invoke(params);
            System.out.println(result);
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }
}


Thanks,
Eddie Johnston










Mime
View raw message