I am trying to use Webservices.
The first thing I have done is to modify the CurrencyConverter example in such a way that it calls my webservice. My webservice is extremely simple. I has a method called HelloWorld. And this method simply returns a string with the text "hello world". Exciting. Indeed.
But I can not get it to work.
Statements:
Sub HttpClient1_ResponseSuccess (Response AsHttpResponse, TaskId AsInt)
Log("ResponseSuccess")
Log(Response)
ProgressDialogHide
Dim Result AsString
Dim ResultLength AsDouble
ResultLength = Response.ContentLength
Result = Response.GetString("UTF8") 'Convert the response to a string
And on the last line it stops. with:
http://192.168.2.109:12749/WS2/Service1.asmx?op=HelloWorld
ResponseSuccess
anywheresoftware.b4a.http.HttpClientWrapper$HttpResponeWrapper@426a4408
main_httpclient1_responsesuccess (B4A line: 126)
Result = Response.GetString("UTF8") 'Convert the response to a string
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1144)
at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:163)
at libcore.io.IoBridge.recvfrom(IoBridge.java:506)
at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)
at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:134)
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:174)
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:188)
at org.apache.http.impl.io.ContentLengthInputStream.close(ContentLengthInputStream.java:121)
at org.apache.http.conn.BasicManagedEntity.streamClosed(BasicManagedEntity.java:179)
at org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:266)
at org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:213)
at java.io.InputStreamReader.close(InputStreamReader.java:145)
at org.apache.http.util.EntityUtils.toString(EntityUtils.java:139)
at anywheresoftware.b4a.http.HttpClientWrapper$HttpResponeWrapper.GetString(HttpClientWrapper.java:489)
at b4a.converter.main._httpclient1_responsesuccess(main.java:698)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA$3.run(BA.java:312)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5414)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
at dalvik.system.NativeStart.main(Native Method)
android.os.NetworkOnMainThreadException
Just before I try to convert the response into a string, I have asked for the length of the response.
It is about 5721 charaters. While the length of the response from teh osiginal CurrencyConverter Webservice was about 97. ????
If I try to invoke my webservice on the server I get as response:
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="Hello'>http://tempuri.org/">Hello World</string>
So, I think the webservice is OK.
Why can i not convert the returned respone into a string? Why is it so long?
Any help would be much appreciated.
The first thing I have done is to modify the CurrencyConverter example in such a way that it calls my webservice. My webservice is extremely simple. I has a method called HelloWorld. And this method simply returns a string with the text "hello world". Exciting. Indeed.
But I can not get it to work.
Statements:
Sub HttpClient1_ResponseSuccess (Response AsHttpResponse, TaskId AsInt)
Log("ResponseSuccess")
Log(Response)
ProgressDialogHide
Dim Result AsString
Dim ResultLength AsDouble
ResultLength = Response.ContentLength
Result = Response.GetString("UTF8") 'Convert the response to a string
And on the last line it stops. with:
http://192.168.2.109:12749/WS2/Service1.asmx?op=HelloWorld
ResponseSuccess
anywheresoftware.b4a.http.HttpClientWrapper$HttpResponeWrapper@426a4408
main_httpclient1_responsesuccess (B4A line: 126)
Result = Response.GetString("UTF8") 'Convert the response to a string
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1144)
at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:163)
at libcore.io.IoBridge.recvfrom(IoBridge.java:506)
at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)
at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:134)
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:174)
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:188)
at org.apache.http.impl.io.ContentLengthInputStream.close(ContentLengthInputStream.java:121)
at org.apache.http.conn.BasicManagedEntity.streamClosed(BasicManagedEntity.java:179)
at org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:266)
at org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:213)
at java.io.InputStreamReader.close(InputStreamReader.java:145)
at org.apache.http.util.EntityUtils.toString(EntityUtils.java:139)
at anywheresoftware.b4a.http.HttpClientWrapper$HttpResponeWrapper.GetString(HttpClientWrapper.java:489)
at b4a.converter.main._httpclient1_responsesuccess(main.java:698)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA$3.run(BA.java:312)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5414)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
at dalvik.system.NativeStart.main(Native Method)
android.os.NetworkOnMainThreadException
Just before I try to convert the response into a string, I have asked for the length of the response.
It is about 5721 charaters. While the length of the response from teh osiginal CurrencyConverter Webservice was about 97. ????
If I try to invoke my webservice on the server I get as response:
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="Hello'>http://tempuri.org/">Hello World</string>
So, I think the webservice is OK.
Why can i not convert the returned respone into a string? Why is it so long?
Any help would be much appreciated.