C# DateTime type over web service with PHP & SOAP

前端 未结 3 1930
花落未央
花落未央 2021-01-27 07:33

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

SOAP __getTypes returns that one of the expected parameter to be

相关标签:
3条回答
  • 2021-01-27 07:48

    "... 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.

    0 讨论(0)
  • 2021-01-27 07:49

    For one web service we use, the service allows for filtering entries by createdAt timestamps with a DateTime object. What I've found to work with this might be a little kludgy but:

    $date = new stdClass();
    $date->DateTime = '2012-01-01T00:00:00Z';
    $date->OffsetMinutes = -480; // Los Angeles offset also can just be set to NULL
    

    Then the params could be:

    $params = array(
     'birthDate' => $date
    );
    

    I've looked for ways to use PHP's native DateTime objects but could find any easier way to go.

    Hope this helps.

    0 讨论(0)
  • 2021-01-27 07:58

    just use: date('Y-m-d\TH:i:s', $dob);

    0 讨论(0)
提交回复
热议问题