Android Question Passing DateTime to SOAP

jaraiza

Active Member
Licensed User
Longtime User
Hi,

How should I pass a DateTime variable through SOAP?

I have a solution to call SOAP WebServices (it took long time to find how to manage it), but until now, I was only required to pass string variables. Now, I'm trying to connect to a WebService that requires the date as DateTime, not as string.

This is an extract:

B4X:
    XML = XML & "<key>" & Main.wsKey & "</key>"
    XML = XML & "<user>" & Main.wsUser & "</user>"
    XML = XML & "<Password>" & Main.wsPW & "</Password>"
    XML = XML & "<licence>" & Main.wsLicRep & "</licence>"
    XML = XML & "<dateINI>" & txtDateIni.Text & " 00:00:00" & "</dateINI>"
    XML = XML & "<dateFIN>" & txtDateFin.Text & " 23:59:59" & "</dateFIN>"

The last two vars are passing "2017-03-22 00:00:00" and "2017-04-20 23:59:59", but when the WebService is called, I get this error:

B4X:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Sender</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">Server was unable to read request. ---&gt; There is an error in XML document (1, 378). ---&gt; The string '2017-03-22 00:00:00' is not a valid AllXsd value.</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>

I used the same WebService in C# and passing the same data as DateTime instead string works fine.

Any ideas?

Thanks!
 

DonManfred

Expert
Licensed User
Longtime User
The last two vars are passing "2017-03-22 00:00:00" and "2017-04-20 23:59:59"
So you are sending "2017-03-22 00:00:00" PLUS & " 00:00:00" ???

What is the content of
txtDateIni.Text
What is the content of
txtDateFin.Text
?
 
Upvote 0

jaraiza

Active Member
Licensed User
Longtime User
So you are sending "2017-03-22 00:00:00" PLUS & " 00:00:00" ???
No, I mean -> txtDateIni.Text & " 00:00:00" <- is passing "2017-03-22 00:00:00" to "<dateINI>" :)

If you check the reported error it says "The string '2017-03-22 00:00:00' is not a valid AllXsd value", so it's being passed correctly.
 
Upvote 0

jaraiza

Active Member
Licensed User
Longtime User
Id the soap service you are using documentated somewhere? URL
I can't publish the URL, but I can post the SOAP
B4X:
<?xml version="1.0" encoding="utf-8"?>

<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>
    <shTXN xmlns="http://tempuri.org/">
      <key>string</key>
      <user>string</user>
      <password>string</password>
      <licence>string</licence>
      <dateINI>dateTime</dateINI>
      <dateFIN>dateTime</dateFIN>
      <cond>string</cond>
      <cond1>short</cond1>
      <cond2>string</cond2>
      <st0>short</st0>
      <st1>short</st1>
      <st2>short</st2>
    </shTXN>
  </soap:Body>
</soap:Envelope>

RESPONSE:
B4X:
<?xml version="1.0" encoding="utf-8"?>

<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>
    <shTXNResponse xmlns="http://tempuri.org/">
      <shTXNResult>string</shTXNResult>
    </shTXNResponse>
  </soap:Body>
</soap:Envelope>

Greets!
 
Upvote 0

jaraiza

Active Member
Licensed User
Longtime User
can you post a working XML?
How does the XML looks like when you sending it with c#?
I dont know c# and i dont know how the "dateTime" should look like

B4X:
string DateIni = "2017-03-22 00:00:00";
string DateFin = "2017-04-22 23:59:59";

DateTime dtDateIni = Convert.ToDateTime(DateIni);
DateTime dtDateFin = Convert.ToDateTime(DateFin);
Ok, now the funny part. dtDateIni and dtDateFin are passed as System.DateTime, but they look like an object:

upload_2017-4-22_4-48-8.png


I hope this is what you wanted to know.

Greets!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Based on https://www.dotnetperls.com/datetime i would say that the String will look like
11/30/2008 12:00:00 AM

Including AM/PM... I would try to set your DateFormat to something which will return such an Datestring when you format it.

Additionally i would use smart string literal. Probably easier to write the XML and you have formatting possibilities using b4a Dateformat methods.
 
Upvote 0

JordiCP

Well-Known Member
Licensed User
Longtime User
I had some recorded frames for a working project using SOAP . The syntax used for timestamps was

B4X:
 ...
 <status>Accepted</status>
  <currentTime>2016-10-10T12:57:57.4837819Z</currentTime>
  <heartbeatInterval>600</heartbeatInterval>
  ...

Don't know if it is a standard, as syntax for fields can be defined in each case, but you can test with this
 
Upvote 0

jaraiza

Active Member
Licensed User
Longtime User
I just ended creating a new WebService (C#) which accepts DateTimes as string, converts them to DateTime, invoke the first WebService and then return the result to my B4a program.

Now I'm having some problems reading the resulting XML, but that's material for a new post.

Thanks everyone :)
 
Upvote 0
Top