import java.io.IOException; import java.net.Authenticator; import java.net.PasswordAuthentication; import java.util.ArrayList; import java.util.List; import org.ksoap2.HeaderProperty; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.PropertyInfo; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapPrimitive; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; import org.xmlpull.v1.XmlPullParserException; import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class Main extends Activity { private final String namespace = "urn:microsoft-dynamics-schemas/codeunit/MonService"; private final String url = "http://[@ip]:7047/DynamicsNAV71/WS/ATLAS%20AUTO/Codeunit/MonService"; private final String soap_action = "urn:microsoft-dynamics-schemas/codeunit/MonService:Hello"; private final String method_name = "Hello"; String great=""; TextView txt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); txt=(TextView)findViewById(R.id.text); Button bt=(Button)findViewById(R.id.btn); bt.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new Task().execute(); } }) ; } public String maMethode(){ try { SoapObject request = new SoapObject(namespace, method_name); //Property which holds input parameters PropertyInfo celsiusPI = new PropertyInfo(); //Set Name celsiusPI.setName("par"); int n=123; //Set Value celsiusPI.setValue(n); celsiusPI.setType(int.class); request.addProperty(celsiusPI); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //envelope.bodyOut=request; envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE transport = new HttpTransportSE(url); try{ List<HeaderProperty> headerList = new ArrayList<HeaderProperty>(); headerList.add(new HeaderProperty("Authorization", "Basic " + org.kobjects.base64.Base64.encode("domain\\user:password".getBytes()))); transport.call(soap_action, envelope); }catch(IOException e ) { e.printStackTrace(); // System.out.println(e.toString()+"1"); great=e.toString(); } catch(XmlPullParserException e) { e.printStackTrace(); //System.out.println(e.toString()+"2"); great=e.toString(); } if(envelope.bodyIn != null){ SoapPrimitive result = (SoapPrimitive) envelope.getResponse(); great= result.toString(); } return great; } catch (Exception e) { e.printStackTrace(); // System.out.println(e.toString()+"" ); great = e.toString(); return great; } } public class Task extends AsyncTask<Void,Void,Void> { @Override protected Void doInBackground(Void... params) { // TODO Auto-generated method stub great=maMethode(); return null; } @Override protected void onPostExecute(Void result) { //Log.i(TAG, "doInBackground"); txt.setText(great); } }}
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:microsoft-dynamics-schemas/codeunit/MonService" targetNamespace="urn:microsoft-dynamics-schemas/codeunit/MonService"> <types> <schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="urn:microsoft-dynamics-schemas/codeunit/MonService"> <element name="Hello"> <complexType> <sequence> <element minOccurs="1" maxOccurs="1" name="par" type="int"/> </sequence> </complexType> </element> <element name="Hello_Result"> <complexType> <sequence> <element minOccurs="1" maxOccurs="1" name="return_value" type="string"/> </sequence> </complexType> </element> </schema> </types> <message name="Hello"> <part name="parameters" element="tns:Hello"/> </message> <message name="Hello_Result"> <part name="parameters" element="tns:Hello_Result"/> </message> <portType name="MonService_Port"> <operation name="Hello"> <input name="Hello" message="tns:Hello"/> <output name="Hello_Result" message="tns:Hello_Result"/> </operation> </portType> <binding name="MonService_Binding" type="tns:MonService_Port"> <binding xmlns="http://schemas.xmlsoap.org/wsdl/soap/" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="Hello"> <operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="urn:microsoft-dynamics-schemas/codeunit/MonService:Hello" style="document"/> <input name="Hello"> <body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/> </input> <output name="Hello_Result"> <body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/> </output> </operation> </binding> <service name="MonService"> <port name="MonService_Port" binding="tns:MonService_Binding"> <address xmlns="http://schemas.xmlsoap.org/wsdl/soap/" location="http://@ip:7047/DynamicsNAV71/WS/ATLAS%20AUTO/Codeunit/MonService"/> </port> </service> </definitions>