F0G F0G - 1 year ago 200
C# Question

C# DateTime type over web service with PHP & SOAP

I work with web services written in C#, with PHP on my (client) side.


returns that one of the expected parameter to be
dateTime birthDate
. I tried to send parameter in different ways, like

$date = new DateTime("now");

I even wrote it just as a string
and so on. I do not get soap exception, but function returns that received
value was

I had a meeting with the developer of web services and he showed me that when he passes
type variable to the function it works properly, but he did it locally in C# and not over the web service, just doing

date = new DateTime(1999,9,9,0,0,0);

What i want to know is how can i pass c#
type from PHP. I guess that i'm doing it right with
or with

I just want to make sure that this part of code is right and if so, search for problem in other place.

UPDATE: What we came to is: they changed code on their side. Data type remains the same (DateTime), I don't have an idea what they did there, but if I get any information, I'll keep this post up to date.

After few years: They just had no idea what they were doing and I got stuck with a problem, that was just impossible to solve by my side. If WSDL requests
and you send it properly (SOAP doesn't throw an exception) and it doesn't work as it should, than you should be looking for the problem on the other side, for sure. They made these and few other tricks and blamed on me to gain some time as their work wasn't nor complete or done properly. They did it well as I was new and only web dev in a company, I was 20 and not very confident with the guys who worked as developers nearly since I was born. Finally when we were working on the last part of the project they said that it took too much time for us to finish it and gave it to other developers. On the last part it was obvious that this project had no future, as the architecture was wrong. That project is not released yet (after 3 years) despite they switched at list 2 companies (which I know) to implement it on client side. This has been the worst opportunity in my professional career.

Answer Source

"... I had a meeting with the developer of web services and he showed me that when he passes System.DateTime type variable to the function it works properly, but he did it locally in C# ..."

The function you try to invoke in the C# web service takes a System.DateTime object as a parameter. I looked it up at MSDN and learned that it is a C# class. PHP's DateTime Class is not the same, so the service probably recognizes an instance of PHP's DateTime class as invalid data. I am not sure how communication works with C# services, but I would assume that it requires a binary representation of a C# System.DateTime object. It means that you could potentially investigate how C#'s System.DateTime object is represented in binary and manually construct and pass the binary data in PHP. This is however incredible time consuming and you have no gurantee that it will actually work.

A better solution would be to use another function in the web service (if it exists) that retrieve primitime data types as parameters instead of C# specific classes. An example would be a similar function in the web service that retrieves an Unix timestamp (in PHP: time()) which the function can use to create its own System.DateTime C# object. Another example could be a function retrieving a date from a formatted string (e.g. "dd.mm.yyy H:i:s").

It would be easier to help you if you were able to retireve the web service developer's local code/example (the one you mentioned) and post it here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download