4

I am working on a Currency Converter application, and I cannot get a proper output (I am getting a zero).

I am using the webservice from http://www.webservicex.net/ws/WSDetails.aspx?CATID=2&WSID=10.

The WSDL declares the function as:

<wsdl:types>
  <s:schema elementFormDefault="qualified" targetNamespace="http://www.webserviceX.NET/">
  <s:element name="ConversionRate">
  <s:complexType>
  <s:sequence>
  <s:element minOccurs="1" maxOccurs="1" name="FromCurrency" type="tns:Currency"/>
  <s:element minOccurs="1" maxOccurs="1" name="ToCurrency" type="tns:Currency"/>
  </s:sequence>
</s:complexType>
</s:element>
<s:simpleType name="Currency">
  <s:restriction base="s:string">
   <s:enumeration value="AFA"/>
   <s:enumeration value="ALL"/>
   <s:enumeration value="DZD"/>
   <s:enumeration value="ARS"/>
   <s:enumeration value="AWG"/>
   <s:enumeration value="AUD"/>
 </s:restriction>
</s:simpleType>
<s:element name="ConversionRateResponse">
  <s:complexType>
  <s:sequence>
  <s:element minOccurs="1" maxOccurs="1" name="ConversionRateResult" type="s:double"/>
  </s:sequence>
  </s:complexType>
  </s:element>
  <s:element name="double" type="s:double"/>
  </s:schema>
</wsdl:types>

My Android class:

public class MainActivity extends Activity {

 private static final String NAMESPACE = "http://www.webserviceX.NET";

private static String URL = "http://www.webserviceX.NET/CurrencyConvertor.asmx?WSDL"; 
private static final String METHOD_NAME = "ConversionRate";
private static final String SOAP_ACTION =  "http://www.webserviceX.NET/ConversionRate";
 private TextView lblResult;   


 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  lblResult = (TextView) findViewById(R.id.result);

  SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 


  PropertyInfo propInfo=new PropertyInfo();
  propInfo.name="FromCurrency";
  propInfo.type=PropertyInfo.STRING_CLASS;
  propInfo.setValue("AFA");


  PropertyInfo propInfo2 = new PropertyInfo();
  propInfo2.name="ToCurrency";
  propInfo2.type = PropertyInfo.STRING_CLASS;
  propInfo2.setValue("AUD");

  request.addProperty(propInfo);
  request.addProperty(propInfo2);

  SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 

  envelope.setOutputSoapObject(request);
  envelope.dotNet=true;

  HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

  try {
   androidHttpTransport.call(SOAP_ACTION, envelope);

   SoapPrimitive  resultsRequestSOAP = (SoapPrimitive) envelope.getResponse();

   lblResult.setText(resultsRequestSOAP.toString());


  } catch (Exception e) {
      lblResult.setText(e.getMessage());

  }

 }

Anybody has suggestion on what is wrong?

THX!

Daniel

Knaks
  • 209
  • 3
  • 11

2 Answers2

1

I think your URL string would be:

private static String URL = "http://www.webserviceX.NET/CurrencyConvertor.asmx";

And try this:

Object resultsRequestSOAP = envelope.getResponse();

instead of this:

SoapPrimitive  resultsRequestSOAP = (SoapPrimitive) envelope.getResponse();
Marcos
  • 4,643
  • 7
  • 33
  • 60
  • @enrmarc I would be happy if you could take a look at my [question on WFS and ksoap2-android](http://stackoverflow.com/questions/9237082/how-to-query-a-web-service-via-post-request-in-android). – JJD Feb 12 '12 at 14:32
  • @JJD I just saw your question, sorry I have no idea. – Marcos Feb 12 '12 at 15:14
  • This answer alone is insufficient without the other answer as well, you need a "/" on the end of the namespace too. – Jonathan Schneider Feb 16 '12 at 21:57
0

Your service description shows that the namespace is http://www.webserviceX.NET/

Try putting the extra /

Parth Doshi
  • 4,200
  • 15
  • 79
  • 129
  • Hmmm, I am still getting a 0 as result :( – Knaks Dec 17 '11 at 11:29
  • First see whether the web service is working fine for any kind of currency provided. If there is a problem with the web service then your can't really help, if not trying debugging your code. Try inserting breakpoints when you are making the request and getting the response. – Parth Doshi Dec 17 '11 at 11:49
  • This is half of the issue, you are right! Take the ?WSDL off of the URL, and it will work – Jonathan Schneider Feb 16 '12 at 21:57