Use Dynamic NAV web services with Android (Java)

elbarto
Member Posts: 3
Hello guys,
since a few days I try to use web services with the Android SDK. Normally it should not be a big problem, because Android supports SOAP and I never had any problem to use web services from webpages. But NAV makes problems.
I haven't got any problems to establish a connection to the webservice, it seems that the request doesn't work...
Take a look:
I get following Errormessage:
org.xmlpull.v1.xmlpullparserexception:
unexpected type (position: END_DOCUMENT null@1:0 in
Java.io.inputstreamreader@44c4d2f0)
The Codeunit "CU_Vendor" has got "Getvendor" a function which returns the name of the first vendor.
I use the ksoap2-Library.
The same code works perfectly with web services from webpages.
Has anybody a idea to solve my problem?
Greetings:
El Barto
since a few days I try to use web services with the Android SDK. Normally it should not be a big problem, because Android supports SOAP and I never had any problem to use web services from webpages. But NAV makes problems.
I haven't got any problems to establish a connection to the webservice, it seems that the request doesn't work...
Take a look:
String great = ""; String namespace = "urn:microsoft-dynamics-schemas/codeunit/CU_Vendor"; String url = "http://mch:7047/DynamicsNAV/WS/CRONUS%20International%20Ltd./Codeunit/CU_Vendor"; String soap_action = "urn:microsoft-dynamics-schemas/Codeunit/CU_Vendor:Getvendor"; String method_name = "Getvendor"; try { SoapObject request = new SoapObject(namespace, method_name); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE transport = new HttpTransportSE(url); transport.call(soap_action, envelope); // Receive Error here! SoapObject result = (SoapObject) envelope.getResponse(); great = result.toString(); } catch (Exception e) { great = e.toString(); } return great; // Out there is a DialogAlert which manages output.
I get following Errormessage:
org.xmlpull.v1.xmlpullparserexception:
unexpected type (position: END_DOCUMENT null@1:0 in
Java.io.inputstreamreader@44c4d2f0)
The Codeunit "CU_Vendor" has got "Getvendor" a function which returns the name of the first vendor.
I use the ksoap2-Library.
The same code works perfectly with web services from webpages.
Has anybody a idea to solve my problem?
Greetings:
El Barto
0
Comments
-
I only this link about connecting from java language to nav webservice. I'm guessing you've already enabled NTLM authentication in config file.
http://blogs.msdn.com/b/freddyk/archive ... -java.aspx0 -
Yes, it's already done.
I think "transport" is not able to handle the xml-response of SOAP-Action.
Very strange. Sadly Android doesn't support xml.bind completely...
According to my knowledge and my great web research, I have to use ksoap2-Libraries.0 -
Hello everyone,
I have successfully used service from Java application (thanks to freddyk blog). What I am trying to do now, is to use ksoap2 library to access web service from android, but I am getting the same error message like elbarto.
Did anyone solve this problem, or does anybody have simple working example of “how to connect NAV web service from android”, that is willing to share?
Here is my code:import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.TextView; 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; public class ProjekatActivity extends Activity { private final String NAMESPACE = "urn:microsoft-dynamics-schemas/page/customer/"; private final String URL = "http://xxx.xxx.xxx.xxx:7047/DynamicsNAV/WS/CRONUS%20Hrvatska%20d.o.o/Page/Customer"; private final String SOAP_ACTION = "http://xxx.xxx.xxx.xxx:7047/DynamicsNAV/WS/CRONUS%20Hrvatska%20d.o.o/Page/Customer:Read"; private final String METHOD_NAME = "Read"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); TextView tv = new TextView(this); String custID = "10000"; PropertyInfo custProp = new PropertyInfo(); custProp.setName("No"); custProp.setValue(custID); custProp.setType(String.class); request.addProperty(custProp); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); try { androidHttpTransport.call(SOAP_ACTION, envelope); SoapPrimitive response = (SoapPrimitive)envelope.getResponse(); tv.setText(response.toString()); setContentView(tv); } catch (Exception e) { e.printStackTrace(); } } }
Where xxx.xxx.xxx.xxx is my local ip address.
In the AndroidManifest.xml I added a line<uses-permission android:name="android.permission.INTERNET" />
Customer page is published through web service form in classic client.
Application fails on this line of code:androidHttpTransport.call(SOAP_ACTION, envelope);
Any help would be appreciated.0 -
public String namespace = "urn:microsoft-dynamics-schemas/page/testcard";
public String url = "http://11.112.111.121:7047/DynamicsNAV/WS/andriod/Page/TestCard?wsdl";
public String soap_action = "urn:microsoft-dynamics-schemas/page/testcard:Read";
public String method_name = "Read";
protected Void doInBackground(Void... params) {
try {
SoapObject request = new SoapObject(namespace, method_name);
//request.addProperty("Username","testuser");
//request.addProperty("Password","test@123");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
NTLMTransport ntlm = new NTLMTransport();
ntlm.debug = true;
ntlm.setCredentials(url, "testuser", "test@123", "android", "");
ntlm.call(soap_action, envelope); // Receive Error here!
//SoapObject result = (SoapObject) envelope.bodyIn;
SoapPrimitive result1 = (SoapPrimitive) envelope.getResponse();
//great = response.toString();
grt11 = result1.toString();
//System.out.println(great);
System.out.println(grt11);
} catch (Exception e) {
e.printStackTrace();
//great = e.toString();
//System.out.println(great);
grt11 = e.toString();
System.out.println(grt11);
}
return null;
}
Got Error:
Attempt to invoke virtual method 'java.lang.String org.ksoap2.serialization.SoapPrimitive.toString()' on a null object reference
Any help would be greatly appreciated.0 -
What if you make an intermediate layer, a web service which gets the SOAP response from NAV and convert that SOAP response in JSON/XML and the android get the data from that web service in either JSON or XML, as android is good in parsing json / xml response.Best Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions