Hand crafted SOAP requests

Put your problem here if it does not fit any of the other categories.

Hand crafted SOAP requests

Postby JEvers » Sat Nov 13, 2010 11:30 pm

I am trying to access a SOAP service without using axis2 and I have managed this in a "normal" java class but when I try to use the Android code below I get a Java.io.exception saying "Permission denied". The permissions in the Android Manifest are
<permission android:name="android.permission.INTERNET"></permission>
<permission android:name="android.permission.ACCESS_NETWORK_STATE"></permission>
<permission android:name="android.permission.READ_PHONE_STATE"></permission>


Any ideas?

Thanks,

Jevers



Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package asd.addrmatch;
  2.  
  3. import asd.addrmatch.R.*;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.OutputStream;
  7. import java.io.OutputStreamWriter;
  8. import java.io.Writer;
  9. import java.net.HttpURLConnection;
  10. import java.net.URL;
  11. import java.net.URLConnection;
  12. import java.util.ArrayList;
  13. import android.app.Activity;
  14. import android.os.Bundle;
  15. import android.view.View;
  16. import android.widget.Button;
  17.  
  18. public class match extends Activity {
  19.           public final static String DEFAULT_SERVER
  20.            = "http://pcdb.qdesk.co.uk/services/DtvService";
  21.           public final static String SOAP_ACTION
  22.            = "\"urn:getTargetProperty\"";
  23.  
  24.     /** Called when the activity is first created. */
  25.     @Override
  26.     public void onCreate(Bundle savedInstanceState) {
  27.         super.onCreate(savedInstanceState);
  28.         setContentView(R.layout.main);
  29.         final Button button = (Button) findViewById(R.id.btnTarget);
  30.         button.setOnClickListener(new android.view.View.OnClickListener() {
  31.             public void onClick(View v) {
  32.             String server = DEFAULT_SERVER;
  33.         try {
  34.             URL u = new URL(server);
  35.             URLConnection uc = u.openConnection();
  36.             HttpURLConnection connection = (HttpURLConnection) uc;
  37.            
  38.             connection.setDoOutput(true);
  39.             connection.setDoInput(true);
  40.             connection.setRequestMethod("POST");
  41.             connection.setAllowUserInteraction(true);
  42.             connection.setRequestProperty("SOAPAction", SOAP_ACTION);
  43.            
  44.             OutputStream out = connection.getOutputStream();
  45.             Writer wout = new OutputStreamWriter(out);
  46.            
  47.             wout.write("<?xml version='1.0'encoding='utf-8'?>\r\n");  
  48.             wout.write("<soap:Envelope ");
  49.             wout.write("xmlns:soap=");
  50.             wout.write(
  51.               "'http://schemas.xmlsoap.org/soap/envelope/' "
  52.             );
  53.             wout.write("xmlns:xsi=");
  54.             wout.write(
  55.               "'http://www.w3.org/2001/XMLSchema-instance' ");
  56.             wout.write("xmlns:xsd=");
  57.             wout.write(
  58.               "'http://www.w3.org/2001/XMLSchema'>\r\n");
  59.             wout.write("  <soap:Body>\r\n");
  60.             wout.write("    <getTargetProperty ");
  61.             wout.write("xmlns='http://dtv.landmarkinfo.co.uk/xsd/'>\r\n");
  62.             wout.write("<udprn>" + "2989787"  + "</udprn>\r\n");
  63.             wout.write("<umrrn>" + "0"  + "</umrrn>\r\n");
  64.             wout.write("</getTargetProperty>");
  65.             wout.write("  </soap:Body>\r\n");
  66.             wout.write("</soap:Envelope>\r\n");
  67.            
  68.             wout.flush();
  69.             wout.close();
  70.            
  71.             InputStream in = connection.getInputStream();
  72.             int c;
  73.             while ((c = in.read()) != -1) System.out.write(c);
  74.             in.close();
  75.  
  76.           }
  77.           catch (IOException e) {
  78.               System.err.println(e.getStackTrace());
  79.             System.err.println(e);
  80.           }
  81.             }});
  82.     }
  83. }    
  84.  
Parsed in 0.045 seconds, using GeSHi 1.0.8.4
JEvers
Freshman
Freshman
 
Posts: 2
Joined: Sat Oct 09, 2010 11:36 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 23 guests