yes, NameValuePair("Fahrenheit","23") would be pretty cute, but it's up to you if you want to do the "footwork" - i.e. is it worth it for your app?. In my case, I went for the simplest processing I could think of - it's dirty but it's quick :

a) replace the arguments in the SOAP envelopes with delimited tokens, eg. %degrees% : 

    <soap:Envelope ...
        <soap:Body> ...
            <Fahrenheit>%degrees%</Fahrenheit>
        </soap:Body>
    </soap:Envelope>

b) put the SOAP envelopes in raw resource files, eg. YOUR_PROJECT/res/raw/fahrenheit

c) invoke the snippet below with something like this:

    String [] args = { "212" };
    postMethod.setRequestBody( mergeArguments( R.raw.fahrenheit, args ) );


	/*
	 * 	This reads in the raw soap xml file given by rId and merges in arguments given by args[].
	 * 	The soap file contains tokens of the form '%arg%' and each time such a token is found, 
	 * 	the next args[] is substituted in the xml. If more tokens than args[] are found, then
	 * 	the last args[] is used repeatedly. 
	 */
	private String mergeArgument( int rId, String [] args ) {
		
		String xml = "";
		int currentArgIndex = 0;
		int noArgs = args.length;
		
                Resources resources = getResources();
                InputStream xmlStream = resources.openRawResource( rId );
		try {
			while ( true ) {
				int b = xmlStream.read();
				if ( b < 1 ) break; // EOF
				
				if ( ( char )b == '%' ) { // substitute next args[]
					xml += args[ currentArgIndex ];
					if ( currentArgIndex < noArgs - 1 ) currentArgIndex++;
					do {	// skip input to end of token
						b = xmlStream.read();
						if ( b < 1 ) break; // EOF
					}
					while ( ( char )b != '%' );
				}
				else xml += String.valueOf( ( char )b );
			} 
			xmlStream.close();
		}
		catch ( IOException e ) {
			Log.e( tag, "IOException'" + e.toString() );
		}
		return( xml );
	}

enjoy!

P.S. don't forget    postMethod.releaseConnection();

joesonic wrote:
Thank really this helped me a lot:

now I have a first dirty working code:

    public void ws() throws Exception{

    	HttpClient client = new HttpClient();

        PostMethod postMethod = new PostMethod(  "http://
www.w3schools.com/webservices/tempconvert.asmx"  );
        postMethod.setRequestHeader( "Content-Type", "text/xml;
charset=utf-8" );
        postMethod.setRequestHeader( "SOAPAction", "http://tempuri.org/
FahrenheitToCelsius"  );
        postMethod.setRequestBody("<soap:Envelope xmlns:xsi=\"http://
www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/
2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/
\"><soap:Body><FahrenheitToCelsius xmlns=\"http://tempuri.org/
\"><Fahrenheit>" +
        		"+" +
        		"23" +
        		"</Fahrenheit></FahrenheitToCelsius></soap:Body></
soap:Envelope>");

        int statusCode = client.executeMethod( postMethod );
        if ( statusCode == 200 ) {  // good response
 
((TextView)findViewById(R.id.text)).setText(postMethod.getStatusLine().toString());
        }
    }

Is it also possible to work with this somehow?

        NameValuePair[] xy = {new NameValuePair("Fahrenheit","23")};
        postMethod.setRequestBody(xy);

On Apr 30, 7:13 am, sauhund <[EMAIL PROTECTED]> wrote:
  
The bad news is: Apache Axis is not in Android BUT the good news is,
you can do this with a simple HTTP POST. Get theSOAPenvelope that
Axis generates for you and POST it yourself with something like this:

        import org.apache.commons.httpclient.HttpClient;
        import org.apache.commons.httpclient.methods.PostMethod;

        HttpClient client = new HttpClient();

        PostMethod postMethod = new PostMethod(  YOUR_ENDPOINT  );
        postMethod.setRequestHeader( "Content-Type", "text/xml;
charset=utf-8" );
        postMethod.setRequestHeader( "SOAPAction", YOUR_OPERATION  );
        postMethod.setRequestBody( YOUR_SOAP_ENVELOPE  );

        int statusCode = client.executeMethod( postMethod );
        if ( statusCode == 200 ) {  // good response
                return( postMethod.getStatusLine().toString()  );
        }

To get theSOAPenvelope, start tcpmon or SOAPMonitor and run your
axis code below. Then copy theSOAPfrom the monitor window and paste
it into your Android code.

If you'd like to expand on that approach, I'd recommend putting theSOAPin a resource file and merging in arguments such as "Mike".

enjoy!

On Apr 25, 12:19 pm,joesonic<[EMAIL PROTECTED]> wrote:

    
Hello,
      
Is it possible to useSOAPWebServices in Android in a simple way. As
an example an ordinary java snippet for webservices is given.
      
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import java.net.*;
      
    public class Test {
      public static void main(String[] args) throws Exception
{
          Service service = new Service();
          Call call = (Call)service.createCall();
      
          String endpoint = "http://www.example.com/soapserver.php";
          call.setTargetEndpointAddress(new URL(endpoint));
          call.setOperationName(new QName("getName"));
      
          String name= "Mike";
          String result= (String)call.invoke(new Object [] {new
String(name)});
      
          System.out.println(result);
      }
  }
      
What's the easiest and fasted way to transfor this for android?
Thanks in advance
      
    


  

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-no...
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to