Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
24
Erster Beitrag:
vor 6 Jahren, 3 Monaten
Letzter Beitrag:
vor 5 Jahren, 10 Monaten
Beteiligte Autoren:
Paul Murray, Arie, Ericus, Alan E, Pragma Tix, DerekT

Two Questions About Consuming Web Services in WinDev Mobile for Android

Startbeitrag von Paul Murray am 22.05.2012 15:04

Greetings All,

I am on WM 15 and I am trying to create a very small application to test the ability to consume a web service and dump the result into a looper control.

Question 1: Is it possible to consume a web service for an Android application in WM 15? If so how, please? Every time I import a web service there are errors telling me various capabilities are not supported for Android? Here is an example importing as version 14 (Soap | Procedures):

Error:The function has no equivalent in WL/Android framework.
n_webservice._STget_counties_by_state_codeResponse_FromXML, Local Procedure, line 10, column 4

When I try to import it as a regular web service I do not get any errors (at first) and I am told by the system that I can use the web service natively in my application.

I enter the following code:

sXml_string is string
sState_code is string
sAndroid_password is string

sState_code = "NJ"
sAndroid_password = "ANDROID"
sXml_string = get_counties_by_state_code(sState_code,sAndroid_password)

When I try to save my work, I get the following error:

Error:Internal Error in Android Generation:Unexpected Value Type: .
w_shuttle_schedule, Initialization, line 0, column 0

Question 2: Is it possible to consume a web service for an Android application in WM 17? I am thinking about upgrading but I don't want to do it and then find out that it doesn't work.

If someone is interested letting me know whether or not this web service can be consumed in an Android App, here is the URL:

http://208.44.86.116/windevmobile/n_webservice.asmx?WSDL

It is a .Net WSDL web service that I created.

There are two arguments:

- state_code (e.g., NY, NJ, CT)
- password = "ANDROID"

The service returns a list of counties for each state_code along with the value of the state_code.

Thanks for any pointers!!

Paul

By the way, if someone has some sample code to:

a) call the web service
b) parse the returned xml document
c) add the info into a looper

That would be really appreciated!!

Antworten:

Hi Paul, I just couldn't wait to do a test.
I spent several hours on webservices and Android in WM16 - no go

But it works when using WM17 :spos:

I tried the code below and it runs in the emulator as well as on my Asus tablet TF101.

WHEN EXCEPTION IN
gc is get_counties_by_state_code
gc.state_code = "NY"
gc.password = "ANDROID"
rp1 is get_counties_by_state_codeResponse
rp1 = get_counties_by_state_code(gc)
Info(rp1.get_counties_by_state_codeResult)
DO
Error(ExceptionInfo(errFullDetails))
END

The rp1.get_counties_by_state_codeResult will give you an XML-string, holding ALBANY, ALLEGANY, BRONX, etc as XML-nodes.

I cannot post it because the forum will remove the XML-syntax.
You need to parse the XML with additional code, but according to hte new features this is easy in Wm17 too.

von Arie - am 22.05.2012 18:13
Paul, this code will give you all "counties"

The "untitled" words are part of your (test)webservice.


x is xmlDocument
x = XMLOpen(rp1.get_counties_by_state_codeResult)
n is int = x.untitled.untitled_row..Occurrence
sCounty is string
FOR EACH child1 OF x.untitled
sCounty = child1.County
Info(sCounty)
END



von Arie - am 22.05.2012 18:31
But unfortunately it only works in the emulator.
On the real device it seems the "FOR EACH" does not find any XML-nodes ????

von Arie - am 22.05.2012 18:34
Thanks, Arie!!

Based on what you sent me I upgraded to WM17 today.

I should get the upgrade for the dongle tomorrow.

Thanks VERY much for the help!!

I will report back on my success (I hope!).

Best,

Paul

von Paul Murray - am 22.05.2012 21:39
Hi Arie,

Your code gave me a big leg up on my project today. I was able to quickly install WM17, import the web services and see the data via the emulator. Very Cool!! Thank you!!

Question, please:

In your code why did you use Child1? Does it matter? Does it equate to a certain level in the XML structure? I have the code working for two different web services. The only thing that I changed in the second one was to substitute 'y' for 'x'.

Question, please:

It appears that you can define a global variable like gGetTrips is XMLDocument. Then you can 'SEE' it when you create a Looper Control when selecting 'Display the data found in an existing variable'. But try as I might, I can't make the connection to this XMLDocument variable. I can see it and navigate some sort of xml structure but it doesn't look like mine and I don't know why it would. There is never a place to get to where the OK button is not grayed out. I was wondering if you have to associate an XML template or XSLT file so that the structure of the xml document is known to the system as opposed to simply being an empty reference. I thought I saw this at the WinDev conference in Vegas last year, but I have not gotten around to downloading all of the files. Ugh.

Question, please:

I have used table controls with success before. But not a looper control. First, I am real fuzzy on how to position it. Should I drag it down to fill the entire space available in the window and it 'knows' to fill down or should I drag it down? The reason that I ask is that I don't 'SEE' anything populating in the looper in emulator mode even though I am getting a postive row number when doing LooperAddLine. Also, just before calling LooperAddLine, I have Info windows that pop up with the correct data. I have currently defined my Looper with three columns and it is filled by programming. Currently I am making a reference to the looper via a tabpage, but it doesn't seem to matter whether or not I do that. Here is the code:


gsConfo = EDT_Confo_4

LooperDeleteAll(LOOP_PaxList)


WHEN EXCEPTION IN
gd is get_pax_list_by_partial_confo

gd.account_no = gsAccount_no
gd.confo_4 = gsConfo
gd.password = gsPassword
rp1 is get_pax_list_by_partial_confoResponse
rp1 = get_pax_list_by_partial_confo(gd)
Info(rp1.get_pax_list_by_partial_confoResult)
DO
Error(ExceptionInfo(errFullDetails))
END

nLap is int

y is xmlDocument
y = XMLOpen(rp1.get_pax_list_by_partial_confoResult)
n is int = y.dw_pax_listing_by_confo.dw_pax_listing_by_confo_row..Occurrence
FOR EACH child1 OF y.dw_pax_listing_by_confo
gsLname = child1.lname
Info("Lname",gsLname)
gsFname = child1.fname
Info("Fname",gsFname)
nLap = LooperAddLine(TAB_Pax_Manifest.LOOP_PaxList,gsLname,gsFname, gdtBoarded)
Info("LooperAddLineResultCode",nLap)

END


TAB_Pax_Manifest[2]..State = Active
TAB_Pax_Manifest[2]..Visible = True
TAB_Pax_Manifest = 2



Last Question:

When I imported the web service it said that I could use the web service natively. So I thought I could simply call it as...

MyXMLDocument = get_pax_list_by_confo(confo)

...and then simply do XMLOpen on the document. Should that work?

Thanks again for all of your help!!

Best,

Paul

von Paul Murray - am 23.05.2012 22:20
By the way, Arie, I was able to get it to deploy and run on my DroidX. It did crash, but not before it successfully executed my first web service. I will work on it. Paul

von Paul Murray - am 23.05.2012 23:11
Hi Paul,
here are some answers.
Child1 - it's just the name of a variable I made up, like x and y
And it is indeed refering to the next level of xmlnodes of 'y.dw_pax_listing_by_confo'

Check the help for xmlNode and xmlAttribute variable types. Together with the xmlDocument you should be able to browse all xml-data. I have to say, I'm not quite into this way of using xml with WD. I did use XMLFirst() and so on in some older projects, because that was the only way then.

About the looper. You first have to drag controls into the looper, like a static control or edit-control. Then you have to add Looper-attributes. When you open the description window, you will see a NEW button. Create attributes and bind them to the controls inside your looper. After that your code (which is ok) will display data.

The looper will fill up the entire space with additional rows automatically. Look at the looper as a sopisticated table-control. A looper with just one column looks like a table. Start with one column and if it is working, set it to 2 or more columns to see what happens.

von Arie - am 24.05.2012 08:57
Thanks Arie for the info on the Looper. It still took me a while to figure it out, but I have it running now.

Odd. The information in the looper shows up fine in the emulator but not at all on my DroidX.

When I deploy, I see two devices that I can deploy to. One says DroidX and it says 'Stopped' so I cannnot deploy to it. The other is some long serial number and it says something like 'Started' or 'Running'. I can deploy to it and I see it on my phone, but still that looper is not working on the device.

Paul

von Paul Murray - am 24.05.2012 14:30
Hi,

I'm using WM17 and trying to import a simple webservice. I can import it, but when I try to compile it, I get errors such as:

Error:The function has no equivalent in WL/Android framework.
Service11._createfilesResponse_FromXML, Local Procedure, line 14, column 14


I've tried importing the service as .Net, as a SOAP, but no joy.

Many thanks for any help,

Alan

von Alan E - am 11.06.2012 14:27
Is this a web service with a URL ending in .asmx?

You should be importing it as .NET.

Did you try running the web service from the IIS server on which the web service is running? You should see a list of methods and be able to type in test data and run the simpler ones.

von Paul Murray - am 11.06.2012 15:47
I gave up to using WX automatic WSDL based code generating. Instead I use SoapUI to retrieve all relevant information and do the requests by using SoapRunXML() and SoapGetResult()
Since I don't own WD Mobile, can you please try this snippet please ?

REPLACE smilies with tem : password no space in between !!

///using Soap 1.1 !!!
PROCEDURE GetStates(LOCAL statecode is string, LOCAL pw is string = "" )

SoapMessage is string // Message to send
SoapAction is string = "http://tempurl.org/get_counties_by_state_code";
SoapResponse is string // Service response String
SoapEndPoint is string = "http://208.44.86.116/windevmobile/n_webservice.asmx";
SoapResponseFile is string = CompleteDir(fExeDir()) + "States_" + DateSys() + Now()+ ".xml" // Temporary SOAP response file

SoapMessage = [




%1
%2



]

// Mixin data
SoapMessage = StringBuild(SoapMessage, statecode, pw )

IF SOAPRunXML(SoapEndPoint, SoapMessage, SoapAction) THEN

SoapResponse = SOAPGetResult(SOAPXMLResult)

IF SoapResponse "" THEN
fSaveText(SoapResponseFile, SoapResponse)
END
END



Iterating over the response can be done by xmlfind/xmlchild/xmldata. I would suggest that you drop the responsefile.. in this case : States.xml into your Project explorer/Xml descriptions. drag and drop from the explorer works fine....
http://soapui.org/
hth Bjoern

von Pragma Tix - am 11.06.2012 20:57
works on WD 16.

statecode NY and pw ANDROID..



--- ALBANY NYALLEGANY NYBRONX NYBROOME NYCATTARAUGUS NYCAYUGA NYCHAUTAUQUA NYCHEMUNG NYCHENANGO NYCLINTON NYCOLUMBIA NYCORTLAND NYDELAWARE NYDUTCHESS NYERIE NYESSEX NYFRANKLIN NYFULTON NYGENESEE NYGREENE NYHAMILTON NYHERKIMER NYJEFFERSON NYKINGS NYLEWIS NYLIVINGSTON NYMADISON NYMONROE NYMONTGOMERY NYNASSAU NYNEW YORK NYNIAGARA NYONEIDA NYONONDAGA NYONTARIO NYORANGE NYORLEANS NYOSWEGO NYOTSEGO NYPUTNAM NYQUEENS NYRENSSELAER NYRICHMOND NYROCKLAND NYSAINT LAWRENCE NYSARATOGA NYSCHENECTADY NYSCHOHARIE NYSCHUYLER NYSENECA NYSTEUBEN NYSUFFOLK NYSULLIVAN NYTIOGA NYTOMPKINS NYULSTER NYWARREN NYWASHINGTON NYWAYNE NYWESTCHESTER NYWYOMING NYYATES NY

von Pragma Tix - am 11.06.2012 21:09
Soap commands and therefore its use is not valid for Android - at least not in the PCS implementation in WM17

von DerekT - am 11.06.2012 22:08
Hi,

Yes, it is a .NET web service and I can run the web service quite happily in IIS on the server and see the methods and get results. And I do try and import it as a .NET service.

I did try the SOAPRunXml command and associated commands and they don't seem to want to run in Android unfortunately.

I find it confusing that other people can import web services just fine and others struggle.

many thanks for any help,

alan

von Alan E - am 12.06.2012 09:10
Hi

I am using WM 17 and imported the webservice with no trouble. Everything in my mobile app is working fine is Android emulator and on the device if I use WiFi. As soon as I use 3G the application crashes with an 'Error occured while running the SOAP query'.

I am not using any soap functions in my code.

Following is what I am using:

NewString is LoginCompany
Response is LoginCompanyResponse
ListCustomer is string
NewString.sCompany=EDT_Company
NewString.sUsername=EDT_UserName
NewString.sPassword=EDT_Password
Response=LoginCompany(NewString)
ListCustomer = Response.LoginCompanyResult

I will appreciate any pointers in the right direction.

Ericus

von Ericus - am 13.10.2012 08:23
Ericus,

For future use you should probably start a new thread for a new question.

This is an app that is referencing a local database?

If so, I would turn off wireless and 3G, pull the battery, start it and try again without any connectivity.

Likewise, when you deploy the app, pay attention to what rights you are giving the app. Possibly some of the rights are for features not available on the device (a guess).

Paul

von Paul Murray - am 13.10.2012 14:54
Thanks for your interest Paul.

I created a new thread 'Windev Mobile Android App' Probably not well described.

Any case my app does not use any local data. The app permissions are only to Call_Phone, Internet, Vibarations and Write_External_Storage.

I'm using a Motorola Razr with Android 4.04.
SDK used is 4.0.3 and minimum version to run app is Android 3.0

Not sure if the above is relevant.

On my development machine browser I can see the webservices and execute the procedures. The same in the emulator browser.

However on the phone browser I get an Access Denied message and I think this is my problem. However I don't know where to start solving this.

If you can offer more pointer I will really appreciate it.


Ericus

von Ericus - am 14.10.2012 08:01
Ericus,
afaik an Android app is not aware of the connection you use, be it 3G of wifi.
It is up to the OS to choose, normally.

Are you sure it is not an 'legal' error from the webservice, denying 3G IP or something like that?

von Arie - am 14.10.2012 19:13
Do you know at what point in your code the app crashes?

von Paul Murray - am 14.10.2012 19:20
Hi Paul

I think it is exactly something from the webservice denying the 3G IP because the browser on the phone reports an Access Denied. It seems as if the application crashes as soon as the request is send to the webservice.

however I am not sure how to enable the Windows 2008 server and IIS to accept the 3G IP call.


Ericus

von Ericus - am 14.10.2012 19:58
Ericus,

There are two separate issues here.

1) Access Denied is coming from one of two places (I am guessing).

1a) When you deploy an Android application there is a point at which you specify what the application is allowed to access within the Android environment.

1b) It is possible that once you deploy the application you may have to give it rights to access the internet via 3G so that you can't send out an app that decides to call a phone sex hotline and rack up lots of charges (e.g., a 900 number).

2) With respect to Windows 2008 and IIS you have to create .Net web services that will be called by the Android Windev for Mobile application client. These can be created using Windev (althought I have not done it) or via something like Visual Studio or PowerBuilder (which I have used to create .Net web services.

You could also try to create a subset of the application and deploy it in order figure out whre the problem is. And you could post that app project for other people to look at and try to deploy as well.

I don't know much about debugging with Windev for Mobile, but you could have some pop up windows in your code that display a message (e.g., 1, 2, 3 4) so that you verify where in the code it crashes.

Hope that helps some.

Paul

von Paul Murray - am 14.10.2012 20:10
Hallo Paul

Quite embarrassing but once I installed all the latest updates for Windev 17 Mobile everything works fine.

Thanks for you assistance.

Ericus Steyn

von Ericus - am 17.10.2012 12:30
Not to worry.

Glad you are up and running!!

Paul

von Paul Murray - am 17.10.2012 19:37
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.