Search code examples
androidwsdlksoap2

Cant pick out parameters from this wsdl to use in webservice call


I need to call the following webservice and I have its corresponding WSDL file. However I cannot get the below code to work.

<wsdl:definitions name="ServiceTestService" targetNamespace="http://Rothman.com/">
<wsdl:types>
<schema>
<import namespace="http://Rothman.com/" schemaLocation="http://Rothmanweb.cloudfoundry.com/services/ServiceTestPort?xsd=servicetest_schema1.xsd"/>
</schema>
</wsdl:types>
<wsdl:message name="WhatIsTheAnswerResponse">
    <wsdl:part element="tns:WhatIsTheAnswerResponse" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="WhatIsTheAnswer">
   <wsdl:part element="tns:WhatIsTheAnswer" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="QuestionSEI">
  <wsdl:operation name="WhatIsTheAnswer">
          <wsdl:input message="tns:WhatIsTheAnswer" name="WhatIsTheAnswer"> </wsdl:input>
          <wsdl:output message="tns:WhatIsTheAnswerResponse" name="WhatIsTheAnswerResponse"></wsdl:output>
    </wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ServiceTestServiceSoapBinding" type="tns:QuestionSEI">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="WhatIsTheAnswer">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="WhatIsTheAnswer">
  <soap:body use="literal"/>
 </wsdl:input>
 <wsdl:output name="WhatIsTheAnswerResponse"><soap:body use="literal"/>
 </wsdl:output>
 </wsdl:operation>
 </wsdl:binding>
 <wsdl:service name="ServiceTestService">
     <wsdl:port binding="tns:ServiceTestServiceSoapBinding" name="ServiceTestPort">
     <soap:address location="http://Rothmanweb.cloudfoundry.com/services/ServiceTestPort"/>
     </wsdl:port>
</wsdl:service>
</wsdl:definitions>

Now I have the following code but I cant seem to find the parameters from the WSDL to connect to this service. The sercvice takes a string as an input and returns a string as an output. I have the following code fragment and I am not sure about the following final static values.

    private static final String NAMESPACE = "http://Rothman.com/"; //ok
private static final String METHOD_NAME = "WhatIsTheAnswer"; //ok

private static final String URL = "http://Rothmanweb.cloudfoundry.com/services/ServiceTestPort?wsdl";   
private static final String SOAP_ACTION = "http://Rothman.com/WhatIsTheAnswer";

These values are used as follows

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);        
    SoapSerializationEnvelope envelope =  new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.setOutputSoapObject(request);
    HttpTransport androidHttpTransport = new HttpTransport(URL);
    try 
    {
        androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
        System.out.println("Received object");
    } catch (Exception e)
    {
        e.printStackTrace();
    }

I would appreciate it if someone could tell me how I could use this code to get a response from this webservice. Are my final variables correct ? The service properly works since I tested it using soapUI


Solution

  • URL with WSDL must be real accesible address from android device. And also imported XSD schema in WSDL must be accesible.

    If your web service requires input string, you must specify PropertyInfo as an input param.

    PropertyInfo methodParam = new PropertyInfo();
    methodParam.setName("string");
    methodParam.setValue(yourString);
    methodParam.setType(PropertyInfo.STRING_CLASS);
    Request.addProperty(methodParam);
    
    
    SoapObject soapObject = new SoapObject(NAMESPACE, methodName);
    envelope.setOutputSoapObject(soapObject);