2

I try to send commands to a Navision web service. To understand the whole connection as best as I can, I want to use at first simple cURL commands.

I experiemented with simple GET Requests on the URL https://IP:PORT/.../Codeunit/Webservices. There I got a very long XML structure with all the commands. Part of the list is a simple echo command where I can send a string and get it back.

This is the discription of it:

<schema elementFormDefault="qualified" targetNamespace="urn:microsoft-dynamics-schemas/codeunit/Webservices" xmlns="http://www.w3.org/2001/XMLSchema">
  <element name="SoundCheck">
    <complexType>
      <sequence>
        <element minOccurs="1" maxOccurs="1" name="p_Text" type="string"/>
      </sequence>
    </complexType>
  </element>
  <element name="SoundCheck_Result">
    <complexType>
      <sequence>
        <element minOccurs="1" maxOccurs="1" name="return_value" type="string"/>
      </sequence>
    </complexType>
  </element>
...

Now my problem is that I don't know how to send the command. I looked in these two special SOAP libraries:

I tried their approches but nothing works. My code snippet now looks like this:

$headers = [
    'Method: GET',
    'Connection: Keep-Alive',
    'User-Agent: PHP-SOAP-CURL',
    'Content-Type: text/xml; charset=utf-8',
    'SOAPAction: "' . $action . '"',
];

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

$response = curl_exec($ch);

return $response;

I tried to send various values of $action but I always get this error:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault>
    <faultcode xmlns:a="urn:microsoft-dynamics-schemas/error">a:System.ArgumentNullParametername: input</faultstring>
    <detail><string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Der Wert darf nicht NULL sein.\nParametername: input</string></detail>
</s:Fault></s:Body></s:Envelope>

Maybe I misunderstood the whole SOAP process with navision, but I also don't found any really good tutorials in the web. What am I doing wrong? Thanks for help!

mgluesenkamp
  • 529
  • 6
  • 19

1 Answers1

0

You should try a real WSDL to PHP generator as it will really ease you the consumption of the SOAP Web Service. It's great to want to understand how it works but you should start by using the right classes.

First, you should not use curl directly so you should use the native PHP SoapClient class. This is the starting point using the WSDL url, then try to call the __getTypes and __getFunctions on your SoapClient instance in order to know what is expected by the SOAP Web Service.

Then try a WSDL to PHP generator such as the PackageGenerator project. It basically loads the "types" and "functions" declared by the WSDL and wraps them to basic Classes and methods that you can then easily use to send the request and receive the response.

Mikaël DELSOL
  • 760
  • 5
  • 15