Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
- private static final String METHOD_NAME = "CelsiusToFahrenheit";
- private static final String NAMESPACE = "http://tempuri.org/";
- private static final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
- TextView tv;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- tv = (TextView)findViewById(R.id.text1);
- SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
- request.addProperty("Celsius", "32");
- SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER11);
- soapEnvelope.dotNet = true;
- soapEnvelope.setOutputSoapObject(request);
- HttpTransportSE aht = new HttpTransportSE(URL);
- try {
- aht.call(SOAP_ACTION, soapEnvelope);
- SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
- tv.setText("Status: " + resultString);
- } catch (Exception e) {
- tv.setText("Problem: " + e.toString());
- }
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- <uses-permission android:name="android.permission.INTERNET" />
- new SerializationConnection().execute(URL);
- class SerializationConnection extends AsyncTask<String, Void, String> {
- protected String doInBackground(String... urls) {
- try {
- SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
- request.addProperty("Celsius", "32");
- SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER11);
- soapEnvelope.dotNet = true;
- soapEnvelope.setOutputSoapObject(request);
- HttpTransportSE aht = new HttpTransportSE(urls[0]);
- aht.call(SOAP_ACTION, soapEnvelope);
- SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
- return "Status: " + resultString;
- } catch (Exception e) {
- return "Problem: " + e.toString();
- }
- }
- protected void onPostExecute(String result) {
- tv.setText(result);
- }
- }
- private Exception exception;
- @Override
- protected Void doInBackground(Void... arg0) {
- try {
- SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
- request.addProperty("Celsius", "32");
- SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER11);
- soapEnvelope.dotNet = true;
- soapEnvelope.setOutputSoapObject(request);
- HttpTransportSE aht = new HttpTransportSE(URL);
- try {
- aht.call(SOAP_ACTION, soapEnvelope);
- resultString = "Status:" + (SoapPrimitive)soapEnvelope.getResponse();
- } catch (Exception e) {
- resultString = "Problem:" + e.toString();
- }
- }
- protected void onPostExecute(Void result) {
- tv.setText("Status: " + resultString);
- }
- StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
- StrictMode.setThreadPolicy(policy);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement