Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem to access Xignite Webservice with Header Authentication
This is my code
and Webservice address
http://www.xignite.com/xCurrencies.asmx?op=GetRealTimeCrossRate[^]

package com.tuan;

import org.apache.http.Header;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportSE;
import org.kxml2.kdom.Element;
import org.kxml2.kdom.Node;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
 
public class Xignite_WSActivity extends Activity {
    /** Called when the activity is first created. */
	
	 private static final String SOAP_ACTION = "http://www.xignite.com/services/GetRealTimeCrossRate";
	    private static final String METHOD_NAME = "GetRealTimeCrossRate";
	    private static final String NAMESPACE = "http://www.xignite.com/services/";
	    private static final String URL = "http://www.xignite.com/xCurrencies.asmx";
	
	TextView tv;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv=(TextView)findViewById(R.id.Textview01);
        //tao request
        SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
       
        //Is this code to access header properly ?
        Request.addProperty("Username", "onlyyou2011@yahoo.com");
        Request.addProperty("Password","12345qwert");
        Request.addProperty("Tracer","tuan123");
       
        Request.addProperty("From","USD");
        Request.addProperty("To","VND");

        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
     //   soapEnvelope.dotNet=true;
 
        
        soapEnvelope.setOutputSoapObject(Request);
        HttpTransportSE httpTransportSE = new HttpTransportSE(URL);
	    AndroidHttpTransport aht = new AndroidHttpTransport(URL);
    
       
       try {
    	   aht.call(SOAP_ACTION, soapEnvelope);
    	   httpTransportSE.call(SOAP_ACTION,soapEnvelope);
    	   SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
    	
    	   tv.setText("Trang Thai"+resultString);
	} catch (Exception e) {
		// TODO: handle exception
		e.printStackTrace();
	}
        
    }
}
Posted
Updated 19-Nov-11 16:48pm
v3

can u share response from xignite
 
Share this answer
 
Running the following code fails for me. If the following lines of code are commented out, the code should run up until the soapEnvelope.getResponse() .


soapEnvelope.setOutputSoapObject(Request);
HttpTransportSE httpTransportSE = new HttpTransportSE(URL);
AndroidHttpTransport aht = new AndroidHttpTransport(URL);


try {
aht.call(SOAP_ACTION, soapEnvelope);
httpTransportSE.call(SOAP_ACTION,soapEnvelope);
SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();

Remove those lines of code and see how it helps.

Try the following sample code if that does solve your issue. We provide all our web service call Via REST and return XML,JSON or CSV


// Send a GET request to the servlet
StringBuffer responseStr = new StringBuffer();
StringBuffer requestUrl = new StringBuffer();
requestUrl.append("http://www.xignite.com/xCurrencies.asmx/GetRealTimeCrossRate");
requestUrl.append("?From=USD");
requestUrl.append("&To=EUR");
requestUrl.append("&Username=onlyyou2011@yahoo.com");
requestUrl.append("&Password=12345qwert");
requestUrl.append("&Tracer=tuan123");
try
{
// Send data
String urlStr = requestUrl.toString();
URL url = new URL(urlStr);
URLConnection conn = url.openConnection ();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null)
{
responseStr.append(line);
}
rd.close();
}
catch (Exception e)
{
e.printStackTrace();
}

result = responseStr.toString();
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900