web services - PHP SOAP request to navision webservice -
for days i've been struggling connection between php webshop , navision server ntlm authentication. connection , authentication done, i'm having problems doing correct request.
for example try use function (itempricediscinventory) retrieve price information.
the url have customer is: http://ip:port/msiteminfotest/ws/saniceve%20bv/codeunit/itempricediscinventory
i have tried 2 methods make request:
curl post raw xml
the raw xml given customer. same xml test program (soacleaner) gives me when entered (local) wsdl file.
$request = ' <inputitempricediscinventory_portgetpricediscinvinformation xmlns="http://xyrow.com"> <body xmlns=""> <getpricediscinvinformation xmlns="urn:microsoft-dynamics-schemas/codeunit/itempricediscinventory"> <itempricediscinventory> <item xmlns="urn:microsoft-dynamics-nav/xmlports/x50005"> <klantnummer /> <artikelnr /> <aantal /> <kortingspercentage1 /> <kortingspercentage2 /> <nettopereenheid /> <beschikbarevoorraad /> <webshopvoorraad /> </item> </itempricediscinventory> <customerno>1234</customerno> <itemno>5678</itemno> <quantityvardec>1</quantityvardec> </getpricediscinvinformation> </body> </inputitempricediscinventory_portgetpricediscinvinformation>'; my request:
$ch = curl_init(); $headers = array( 'method: post', 'connection: keep-alive', 'content-type: text/xml; charset=utf-8', "host: {$ip}:{$port}", "accept: */*" ); curl_setopt($ch, curlopt_url, $url ); curl_setopt($ch, curlopt_returntransfer, true ); curl_setopt($ch, curlopt_post, true ); curl_setopt($ch, curlopt_postfields, $request); curl_setopt($ch, curlopt_userpwd, 'usr:pass'); curl_setopt($ch, curlopt_httpauth, curlauth_ntlm ); curl_setopt($ch, curlopt_http_version, curl_http_version_1_1); curl_setopt($ch, curlopt_httpheader, $headers); curl_setopt($ch, curlopt_failonerror, 0); this returns wsdl file, no matter post values include. if include header 'soapaction: "itempricediscinventory"' gives me 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.net.webexception</faultcode><faultstring xml:lang="nl-nl">soap message invalid!</faultstring><detail><string xmlns="http://schemas.microsoft.com/2003/10/serialization/">soap message invalid!</string></detail></s:fault></s:body></s:envelope> the wsdl looks like:
<definitions targetnamespace="urn:microsoft-dynamics-schemas/codeunit/itempricediscinventory" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:microsoft-dynamics-schemas/codeunit/itempricediscinventory"> <types> <schema elementformdefault="qualified" targetnamespace="urn:microsoft-dynamics-nav/xmlports/x50005" xmlns="http://www.w3.org/2001/xmlschema" xmlns:tns="urn:microsoft-dynamics-nav/xmlports/x50005"> <complextype name="item"> <sequence> <element minoccurs="1" maxoccurs="1" name="klantnummer" type="string"/> <element minoccurs="1" maxoccurs="1" name="artikelnr" type="string"/> <element minoccurs="1" maxoccurs="1" name="aantal" type="string"/> <element minoccurs="1" maxoccurs="1" name="kortingspercentage1" type="string"/> <element minoccurs="1" maxoccurs="1" name="kortingspercentage2" type="string"/> <element minoccurs="1" maxoccurs="1" name="nettopereenheid" type="string"/> <element minoccurs="1" maxoccurs="1" name="beschikbarevoorraad" type="string"/> <element minoccurs="1" maxoccurs="1" name="webshopvoorraad" type="string"/> </sequence> </complextype> <complextype name="itempricediscinvinfo" mixed="true"> <sequence> <element minoccurs="1" maxoccurs="1" name="item" type="tns:item"/> </sequence> </complextype> <element name="itempricediscinvinfo" type="tns:itempricediscinvinfo"/> </schema> <schema elementformdefault="qualified" targetnamespace="urn:microsoft-dynamics-schemas/codeunit/itempricediscinventory" xmlns="http://www.w3.org/2001/xmlschema"> <element name="getpricediscinvinformation"> <complextype> <sequence> <element minoccurs="1" maxoccurs="1" name="itempricediscinventory" type="q1:itempricediscinvinfo" xmlns:q1="urn:microsoft-dynamics-nav/xmlports/x50005"/> <element minoccurs="1" maxoccurs="1" name="customerno" type="string"/> <element minoccurs="1" maxoccurs="1" name="itemno" type="string"/> <element minoccurs="1" maxoccurs="1" name="quantityvardec" type="decimal"/> </sequence> </complextype> </element> <element name="getpricediscinvinformation_result"> <complextype> <sequence> <element minoccurs="1" maxoccurs="1" name="itempricediscinventory" type="q2:itempricediscinvinfo" xmlns:q2="urn:microsoft-dynamics-nav/xmlports/x50005"/> </sequence> </complextype> </element> </schema> </types> <message name="getpricediscinvinformation"> <part name="parameters" element="tns:getpricediscinvinformation"/> </message> <message name="getpricediscinvinformation_result"> <part name="parameters" element="tns:getpricediscinvinformation_result"/> </message> <porttype name="itempricediscinventory_port"> <operation name="getpricediscinvinformation"> <input name="getpricediscinvinformation" message="tns:getpricediscinvinformation"/> <output name="getpricediscinvinformation_result" message="tns:getpricediscinvinformation_result"/> </operation> </porttype> <binding name="itempricediscinventory_binding" type="tns:itempricediscinventory_port"> <binding transport="http://schemas.xmlsoap.org/soap/http" xmlns="http://schemas.xmlsoap.org/wsdl/soap/"/> <operation name="getpricediscinvinformation"> <operation soapaction="urn:microsoft-dynamics-schemas/codeunit/itempricediscinventory:getpricediscinvinformation" style="document" xmlns="http://schemas.xmlsoap.org/wsdl/soap/"/> <input name="getpricediscinvinformation"> <body use="literal" xmlns="http://schemas.xmlsoap.org/wsdl/soap/"/> </input> <output name="getpricediscinvinformation_result"> <body use="literal" xmlns="http://schemas.xmlsoap.org/wsdl/soap/"/> </output> </operation> </binding> <service name="itempricediscinventory"> <port name="itempricediscinventory_port" binding="tns:itempricediscinventory_binding"> <address location="http://ip:port/msiteminfotest/ws/saniceve%20bv/codeunit/itempricediscinventory" xmlns="http://schemas.xmlsoap.org/wsdl/soap/"/> </port> </service> </definitions> php soapclient request
ok, thought, try soap functionality of php. used ntlmsoapclient class authentication, seems ok. if construct client in wsdl mode, url given above, can't parse wsdl:
[wsdl] soap-error: parsing wsdl: couldn't load 'url' : start tag expected, '<' but if in non wsdl mode, , give location in parameters, i'm having result...
stream_wrapper_unregister('http'); stream_wrapper_register('http', 'myserviceproviderntlmstream') or die("failed register protocol"); $client = new myservicentlmsoapclient(null,array( 'location' => $url, 'uri' => "http://schemas.xmlsoap.org/wsdl/soap/", 'trace' => 1)); $itempricediscinventory = array( "item" => array( "klantnummer" => null, "artikelnr" => null, "aantal" => null, "kortingspercentage" => null, "nettopereenheid" => null, "voorraad" => null ) ); $params = array( "itempricediscinventory" => $itempricediscinventory, "customerno" => '0000265', "itemno" => 'san483539', "quantityvardec" => '1.0' ); echo $client->getpricediscinvinformation($params); stream_wrapper_restore('http'); this results in error. if last request , response gives me:
<?xml version="1.0" encoding="utf-8"?> <soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" soap-env:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/"> <soap-env:body> <ns1:getpricediscinvinformation> <param0 xsi:type="ns2:map"> <item> <key xsi:type="xsd:string">itempricediscinventory</key> <value xsi:type="ns2:map"> <item> <key xsi:type="xsd:string">item</key> <value xsi:type="ns2:map"> <item> <key xsi:type="xsd:string">klantnummer</key> <value xsi:nil="true"/> </item> <item> <key xsi:type="xsd:string">artikelnr</key> <value xsi:nil="true"/> </item> <item> <key xsi:type="xsd:string">aantal</key> <value xsi:nil="true"/> </item> <item> <key xsi:type="xsd:string">kortingspercentage</key> <value xsi:nil="true"/> </item> <item> <key xsi:type="xsd:string">nettopereenheid</key> <value xsi:nil="true"/> </item> <item> <key xsi:type="xsd:string">voorraad</key> <value xsi:nil="true"/> </item> </value> </item> </value> </item> <item> <key xsi:type="xsd:string">customerno</key> <value xsi:type="xsd:string">0000265</value> </item> <item> <key xsi:type="xsd:string">itemno</key> <value xsi:type="xsd:string">san483539</value> </item> <item> <key xsi:type="xsd:string">quantityvardec</key> <value xsi:type="xsd:string">1.0</value> </item> </param0> </ns1:getpricediscinvinformation> </soap-env:body> </soap-env:envelope> response:
<s:envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:body> <s:fault> <faultcode xmlns:a="urn:microsoft-dynamics-schemas/error">a:microsoft.dynamics.nav.service.webservices.servicebrokerexception</faultcode> <faultstring xml:lang="nl-nl">parameter itempricediscinventory in method getpricediscinvinformation in service itempricediscinventory null!</faultstring> <detail> <string xmlns="http://schemas.microsoft.com/2003/10/serialization/">parameter itempricediscinventory in method getpricediscinvinformation in service itempricediscinventory null!</string> </detail> </s:fault> </s:body> so, seems trying parse it, request not in correct format. note: don't know uri parameter has be. can read wsdl?
if @ request customer gave me , soap request, differs lot (first 1 doesn't looks soap @ all), soap request, seems bit closer.
any thoughts on this?
i figured out. first thought there wrong namespaces in request.
i saved wsdl file on our own server, , used soapclient in wsdl mode, navision server location. worked!
i don't know why can't use direct url in wsdl mode, acceptable workaround.
Comments
Post a Comment