Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

J2ME + Web Service Client

  • 20-04-2009 6:28pm
    #1
    Registered Users, Registered Users 2 Posts: 269 ✭✭


    I am trying to create a J2ME web services client application i have seen this tutorial on netbeans i followed it and created the following classes/wsdl however i am having difficulty connecting the midlet application with these classes

    I bascially want to create a single textfield and ok button that will send the value in the textfield of to the web service in this case the kilometerstoMiles
    can anyone point me in the right direction.

    I dont have much experience with J2ME http://www.netbeans.org/kb/60/mobility/midp-webservices.html

    I am already connecting my web services with a J2EE web application i also want to connect my webservices to a mobile device through J2ME as a bit of extra functionality can anyone help
    package distanceconverterservice;
    
    import javax.xml.rpc.JAXRPCException;
    import javax.xml.namespace.QName;
    import javax.microedition.xml.rpc.Operation;
    import javax.microedition.xml.rpc.Type;
    import javax.microedition.xml.rpc.ComplexType;
    import javax.microedition.xml.rpc.Element;
    
    public class DistanceConverterService_Stub implements DistanceConverterService, javax.xml.rpc.Stub {
    
        private String[] _propertyNames;
        private Object[] _propertyValues;
    
        public DistanceConverterService_Stub() {
            _propertyNames = new String[] { ENDPOINT_ADDRESS_PROPERTY };
            _propertyValues = new Object[] { "http://89.101.115.146:8080/TravelWebService/services/DistanceConverterService.DistanceConverterServiceHttpSoap11Endpoint/" };
        }
    
        public void _setProperty( String name, Object value ) {
            int size = _propertyNames.length;
            for (int i = 0; i < size; ++i) {
                if( _propertyNames[i].equals( name )) {
                    _propertyValues[i] = value;
                    return;
                }
            }
            String[] newPropNames = new String[size + 1];
            System.arraycopy(_propertyNames, 0, newPropNames, 0, size);
            _propertyNames = newPropNames;
            Object[] newPropValues = new Object[size + 1];
            System.arraycopy(_propertyValues, 0, newPropValues, 0, size);
            _propertyValues = newPropValues;
    
            _propertyNames[size] = name;
            _propertyValues[size] = value;
        }
    
        public Object _getProperty(String name) {
            for (int i = 0; i < _propertyNames.length; ++i) {
                if (_propertyNames[i].equals(name)) {
                    return _propertyValues[i];
                }
            }
            if (ENDPOINT_ADDRESS_PROPERTY.equals(name) || USERNAME_PROPERTY.equals(name) || PASSWORD_PROPERTY.equals(name)) {
                return null;
            }
            if (SESSION_MAINTAIN_PROPERTY.equals(name)) {
                return new Boolean(false);
            }
            throw new JAXRPCException("Stub does not recognize property: " + name);
        }
    
        protected void _prepOperation(Operation op) {
            for (int i = 0; i < _propertyNames.length; ++i) {
                op.setProperty(_propertyNames[i], _propertyValues[i].toString());
            }
        }
    
        public String MilestoKilometers(String Miles) throws java.rmi.RemoteException {
            Object inputObject[] = new Object[] {
                Miles
            };
    
            Operation op = Operation.newInstance( _qname_operation_MilestoKilometers, _type_MilestoKilometers, _type_MilestoKilometersResponse );
            _prepOperation( op );
            op.setProperty( Operation.SOAPACTION_URI_PROPERTY, "urn:MilestoKilometers" );
            Object resultObj;
            try {
                resultObj = op.invoke( inputObject );
            } catch( JAXRPCException e ) {
                Throwable cause = e.getLinkedCause();
                if( cause instanceof java.rmi.RemoteException ) {
                    throw (java.rmi.RemoteException) cause;
                }
                throw e;
            }
    
            return (String )((Object[])resultObj)[0];
        }
    
        public String KilometerstoMiles(String Kilometers) throws java.rmi.RemoteException {
            Object inputObject[] = new Object[] {
                Kilometers
            };
    
            Operation op = Operation.newInstance( _qname_operation_KilometerstoMiles, _type_KilometerstoMiles, _type_KilometerstoMilesResponse );
            _prepOperation( op );
            op.setProperty( Operation.SOAPACTION_URI_PROPERTY, "urn:KilometerstoMiles" );
            Object resultObj;
            try {
                resultObj = op.invoke( inputObject );
            } catch( JAXRPCException e ) {
                Throwable cause = e.getLinkedCause();
                if( cause instanceof java.rmi.RemoteException ) {
                    throw (java.rmi.RemoteException) cause;
                }
                throw e;
            }
    
            return (String )((Object[])resultObj)[0];
        }
    
        protected static final QName _qname_operation_KilometerstoMiles = new QName( "http://utilities.travel.ie", "KilometerstoMiles" );
        protected static final QName _qname_operation_MilestoKilometers = new QName( "http://utilities.travel.ie", "MilestoKilometers" );
        protected static final QName _qname_KilometerstoMilesResponse = new QName( "http://utilities.travel.ie", "KilometerstoMilesResponse" );
        protected static final QName _qname_KilometerstoMiles = new QName( "http://utilities.travel.ie", "KilometerstoMiles" );
        protected static final QName _qname_MilestoKilometersResponse = new QName( "http://utilities.travel.ie", "MilestoKilometersResponse" );
        protected static final QName _qname_MilestoKilometers = new QName( "http://utilities.travel.ie", "MilestoKilometers" );
        protected static final Element _type_KilometerstoMiles;
        protected static final Element _type_KilometerstoMilesResponse;
        protected static final Element _type_MilestoKilometersResponse;
        protected static final Element _type_MilestoKilometers;
    
        static {
            _type_KilometerstoMilesResponse = new Element( _qname_KilometerstoMilesResponse, _complexType( new Element[] {
                new Element( new QName( "http://utilities.travel.ie", "return" ), Type.STRING, 0, 1, true )}), 1, 1, false );
            _type_KilometerstoMiles = new Element( _qname_KilometerstoMiles, _complexType( new Element[] {
                new Element( new QName( "http://utilities.travel.ie", "Kilometers" ), Type.STRING, 0, 1, true )}), 1, 1, false );
            _type_MilestoKilometers = new Element( _qname_MilestoKilometers, _complexType( new Element[] {
                new Element( new QName( "http://utilities.travel.ie", "Miles" ), Type.STRING, 0, 1, true )}), 1, 1, false );
            _type_MilestoKilometersResponse = new Element( _qname_MilestoKilometersResponse, _complexType( new Element[] {
                new Element( new QName( "http://utilities.travel.ie", "return" ), Type.STRING, 0, 1, true )}), 1, 1, false );
        }
    
        private static ComplexType _complexType( Element[] elements ) {
            ComplexType result = new ComplexType();
            result.elements = elements;
            return result;
        }
    }
    
    
    
    
    package distanceconverterservice;
    import javax.xml.namespace.QName;
    
    public interface DistanceConverterService extends java.rmi.Remote {
    
        /**
         *
         */
        public String MilestoKilometers(String Miles) throws java.rmi.RemoteException;
    
        /**
         *
         */
        public String KilometerstoMiles(String Kilometers) throws java.rmi.RemoteException;
    
    }
    
    
    <?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://utilities.travel.ie" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://utilities.travel.ie">
        <wsdl:documentation>
    		
    	</wsdl:documentation>
        <wsdl:types>
            <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://utilities.travel.ie">
                <xs:element name="KilometerstoMiles">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element minOccurs="0" name="Kilometers" nillable="true" type="xs:string"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="KilometerstoMilesResponse">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="MilestoKilometers">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element minOccurs="0" name="Miles" nillable="true" type="xs:string"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="MilestoKilometersResponse">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:schema>
        </wsdl:types>
        <wsdl:message name="KilometerstoMilesRequest">
            <wsdl:part name="parameters" element="ns:KilometerstoMiles"/>
        </wsdl:message>
        <wsdl:message name="KilometerstoMilesResponse">
            <wsdl:part name="parameters" element="ns:KilometerstoMilesResponse"/>
        </wsdl:message>
        <wsdl:message name="MilestoKilometersRequest">
            <wsdl:part name="parameters" element="ns:MilestoKilometers"/>
        </wsdl:message>
        <wsdl:message name="MilestoKilometersResponse">
            <wsdl:part name="parameters" element="ns:MilestoKilometersResponse"/>
        </wsdl:message>
        <wsdl:portType name="DistanceConverterServicePortType">
            <wsdl:operation name="KilometerstoMiles">
                <wsdl:input message="ns:KilometerstoMilesRequest" wsaw:Action="urn:KilometerstoMiles"/>
                <wsdl:output message="ns:KilometerstoMilesResponse" wsaw:Action="urn:KilometerstoMilesResponse"/>
            </wsdl:operation>
            <wsdl:operation name="MilestoKilometers">
                <wsdl:input message="ns:MilestoKilometersRequest" wsaw:Action="urn:MilestoKilometers"/>
                <wsdl:output message="ns:MilestoKilometersResponse" wsaw:Action="urn:MilestoKilometersResponse"/>
            </wsdl:operation>
        </wsdl:portType>
        <wsdl:binding name="DistanceConverterServiceSoap11Binding" type="ns:DistanceConverterServicePortType">
            <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
            <wsdl:operation name="KilometerstoMiles">
                <soap:operation soapAction="urn:KilometerstoMiles" style="document"/>
                <wsdl:input>
                    <soap:body use="literal"/>
                </wsdl:input>
                <wsdl:output>
                    <soap:body use="literal"/>
                </wsdl:output>
            </wsdl:operation>
            <wsdl:operation name="MilestoKilometers">
                <soap:operation soapAction="urn:MilestoKilometers" style="document"/>
                <wsdl:input>
                    <soap:body use="literal"/>
                </wsdl:input>
                <wsdl:output>
                    <soap:body use="literal"/>
                </wsdl:output>
            </wsdl:operation>
        </wsdl:binding>
        <wsdl:binding name="DistanceConverterServiceSoap12Binding" type="ns:DistanceConverterServicePortType">
            <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
            <wsdl:operation name="KilometerstoMiles">
                <soap12:operation soapAction="urn:KilometerstoMiles" style="document"/>
                <wsdl:input>
                    <soap12:body use="literal"/>
                </wsdl:input>
                <wsdl:output>
                    <soap12:body use="literal"/>
                </wsdl:output>
            </wsdl:operation>
            <wsdl:operation name="MilestoKilometers">
                <soap12:operation soapAction="urn:MilestoKilometers" style="document"/>
                <wsdl:input>
                    <soap12:body use="literal"/>
                </wsdl:input>
                <wsdl:output>
                    <soap12:body use="literal"/>
                </wsdl:output>
            </wsdl:operation>
        </wsdl:binding>
        <wsdl:binding name="DistanceConverterServiceHttpBinding" type="ns:DistanceConverterServicePortType">
            <http:binding verb="POST"/>
            <wsdl:operation name="KilometerstoMiles">
                <http:operation location="DistanceConverterService/KilometerstoMiles"/>
                <wsdl:input>
                    <mime:content type="text/xml" part="KilometerstoMiles"/>
                </wsdl:input>
                <wsdl:output>
                    <mime:content type="text/xml" part="KilometerstoMiles"/>
                </wsdl:output>
            </wsdl:operation>
            <wsdl:operation name="MilestoKilometers">
                <http:operation location="DistanceConverterService/MilestoKilometers"/>
                <wsdl:input>
                    <mime:content type="text/xml" part="MilestoKilometers"/>
                </wsdl:input>
                <wsdl:output>
                    <mime:content type="text/xml" part="MilestoKilometers"/>
                </wsdl:output>
            </wsdl:operation>
        </wsdl:binding>
        <wsdl:service name="DistanceConverterService">
            <wsdl:port name="DistanceConverterServiceHttpSoap11Endpoint" binding="ns:DistanceConverterServiceSoap11Binding">
                <soap:address location="http://89.101.115.146:8080/TravelWebService/services/DistanceConverterService.DistanceConverterServiceHttpSoap11Endpoint/"/>
            </wsdl:port>
            <wsdl:port name="DistanceConverterServiceHttpSoap12Endpoint" binding="ns:DistanceConverterServiceSoap12Binding">
                <soap12:address location="http://89.101.115.146:8080/TravelWebService/services/DistanceConverterService.DistanceConverterServiceHttpSoap12Endpoint/"/>
            </wsdl:port>
            <wsdl:port name="DistanceConverterServiceHttpEndpoint" binding="ns:DistanceConverterServiceHttpBinding">
                <http:address location="http://89.101.115.146:8080/TravelWebService/services/DistanceConverterService.DistanceConverterServiceHttpEndpoint/"/>
            </wsdl:port>
        </wsdl:service>
    </wsdl:definitions>
    
    
    
    
    
    <?xml version="1.0" encoding="UTF-8"?>
    <wsclientconfig serviceType="jsr-172" version="1.0">
        <client>
            <project>MobileApplication1</project>
            <class location="${src.dir}" type="distanceconverterservice.DistanceConverterService"/>
            <property name="DataBinding" value="true"/>
            <property name="cldc11" value="true"/>
        </client>
        <services>
            <service file="DistanceConverterService.wsdl" url="http://localhost:8080/TravelWebService/services/DistanceConverterService?wsdl"/>
        </services>
    </wsclientconfig>
    
    
    


Advertisement