I have created a web service using this tutorial . I have successfully created web service client . Its working fine for me. Now I want call this web service from android. I am trying since two days without any result. Please help me to fix this.
private static String SOAP_ACTION = "http://localhost:8080/MyFirstWebService/services/FirstWebService";
private static String NAMESPACE = "http://localhost:8080/MyFirstWebService/services/";
private static String METHOD_NAME = "addTwoNumbers";
private static String URL = "http://localhost:8080/MyFirstWebService/services/FirstWebService?wsdl";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Initialize soap request + add parameters
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("firstNumber",""+5);
request.addProperty("secondNumber",""+5);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
// Make the soap call.
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
} catch (Exception e) {
e.printStackTrace();
}
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;
Log.d("prabhu","result is ....."+result);
if(result != null){
TextView t = (TextView)this.findViewById(R.id.resultbox);
Log.d("prabhu","result is ....."+result.getProperty(0).toString());
t.setText("SOAP response:\n\n" + result.getProperty(0).toString());
}
}
This is my wsdl :
http://localhost:8080/MyFirstWebService/services/FirstWebService?wsdl
<?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://sencide.com" 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://sencide.com">
<wsdl:documentation>Please Type your service description here</wsdl:documentation>
- <wsdl:types>
- <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://sencide.com">
- <xs:element name="addTwoNumbers">
- <xs:complexType>
- <xs:sequence>
<xs:element minOccurs="0" name="firstNumber" type="xs:int" />
<xs:element minOccurs="0" name="secondNumber" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="addTwoNumbersResponse">
- <xs:complexType>
- <xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
- <wsdl:message name="addTwoNumbersRequest">
<wsdl:part name="parameters" element="ns:addTwoNumbers" />
</wsdl:message>
- <wsdl:message name="addTwoNumbersResponse">
<wsdl:part name="parameters" element="ns:addTwoNumbersResponse" />
</wsdl:message>
- <wsdl:portType name="FirstWebServicePortType">
- <wsdl:operation name="addTwoNumbers">
<wsdl:input message="ns:addTwoNumbersRequest" wsaw:Action="urn:addTwoNumbers" />
<wsdl:output message="ns:addTwoNumbersResponse" wsaw:Action="urn:addTwoNumbersResponse" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="FirstWebServiceSoap11Binding" type="ns:FirstWebServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <wsdl:operation name="addTwoNumbers">
<soap:operation soapAction="urn:addTwoNumbers" 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="FirstWebServiceSoap12Binding" type="ns:FirstWebServicePortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <wsdl:operation name="addTwoNumbers">
<soap12:operation soapAction="urn:addTwoNumbers" 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="FirstWebServiceHttpBinding" type="ns:FirstWebServicePortType">
<http:binding verb="POST" />
- <wsdl:operation name="addTwoNumbers">
<http:operation location="addTwoNumbers" />
- <wsdl:input>
<mime:content type="text/xml" part="parameters" />
</wsdl:input>
- <wsdl:output>
<mime:content type="text/xml" part="parameters" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="FirstWebService">
- <wsdl:port name="FirstWebServiceHttpSoap11Endpoint" binding="ns:FirstWebServiceSoap11Binding">
<soap:address location="http://localhost:8080/MyFirstWebService/services/FirstWebService.FirstWebServiceHttpSoap11Endpoint/" />
</wsdl:port>
- <wsdl:port name="FirstWebServiceHttpSoap12Endpoint" binding="ns:FirstWebServiceSoap12Binding">
<soap12:address location="http://localhost:8080/MyFirstWebService/services/FirstWebService.FirstWebServiceHttpSoap12Endpoint/" />
</wsdl:port>
- <wsdl:port name="FirstWebServiceHttpEndpoint" binding="ns:FirstWebServiceHttpBinding">
<http:address location="http://localhost:8080/MyFirstWebService/services/FirstWebService.FirstWebServiceHttpEndpoint/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>