Jump to content

Recommended Posts

I am writing my first php SOAP application, to talk with a POS system. I have the thing working kinda, but I am still unsure exactly the relationship between my SOAP app and the WSDL the POS company gave me to copy from. There just seems to be a lot of info that I'm not sure what is for.

 

So far, when the POS sends the request to my php script, I have it working to where the data is grabbed, inserted into the DB, and the a response is sent. But I am still getting this error:

 

There was a problem communicating with the web service.  More information: Value cannot be null.

Parameter name: s

 

I am not sure what parameter name s is, or how it relates to anything.

 

Any help would be appreciated since I am more than a little lost.

 

James

 

Link to comment
https://forums.phpfreaks.com/topic/166726-php-and-soap/
Share on other sites

here is my code:

 

<?php 

function _del_p(&$ary) {
    foreach ($ary as $k=>$v) {
        if ($k==='_p') unset($ary[$k]);
        elseif (is_array($ary[$k])) _del_p($ary[$k]);
    }
}

function ImportRMSProducts(&$string) { 

    $parser = xml_parser_create();
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    xml_parse_into_struct($parser, $string, $vals, $index);
    xml_parser_free($parser);

    $mnary=array();
    $ary=&$mnary;
    foreach ($vals as $r) {
        $t=$r['tag'];
        if ($r['type']=='open') {
            if (isset($ary[$t])) {
                if (isset($ary[$t][0])) $ary[$t][]=array(); else $ary[$t]=array($ary[$t], array());
                $cv=&$ary[$t][count($ary[$t])-1];
            } else $cv=&$ary[$t];
            if (isset($r['attributes'])) {foreach ($r['attributes'] as $k=>$v) $cv['_a'][$k]=$v;}
            $cv['_c']=array();
            $cv['_c']['_p']=&$ary;
            $ary=&$cv['_c'];

        } elseif ($r['type']=='complete') {
            if (isset($ary[$t])) { // same as open
                if (isset($ary[$t][0])) $ary[$t][]=array(); else $ary[$t]=array($ary[$t], array());
                $cv=&$ary[$t][count($ary[$t])-1];
            } else $cv=&$ary[$t];
            if (isset($r['attributes'])) {foreach ($r['attributes'] as $k=>$v) $cv['_a'][$k]=$v;}
            $cv['_v']=(isset($r['value']) ? $r['value'] : '');

        } elseif ($r['type']=='close') {
            $ary=&$ary['_p'];
        }
    }    
    

    _del_p($mnary);


$xml_response = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<XMLResponse>";

mysql_connect("localhost", "dubcorpm_test", "1234") or die(mysql_error());
mysql_select_db("dubcorpm_test") or die(mysql_error());

foreach($mnary[Products][_c][ProductItem] as $k=>$v){

$productcode = $v[_c][itemCode][_v];

$xml_response.= "<Product Code=\"".$productcode."\">
                 <Error Code=\"0\">Success</Error>
                 </Product>";

mysql_query("INSERT INTO test (data,id) VALUES ('$productcode','1')") or die(mysql_error());
} 

$xml_response.= "</XMLResponse>";

return $xml_response;
}


   $server = new SoapServer(null, 
      array('uri' => "urn://www.dubcorp.com/test/soap.php"));
   $server->addFunction("ImportRMSProducts"); 
   $server->addFunction("_del_p"); 
   $server->handle(); 
?>

 

I wrote a script to test the output here:

 

http://dubcorp.com/test/soapclient.php

 

Any ideas??

Link to comment
https://forums.phpfreaks.com/topic/166726-php-and-soap/#findComment-879177
Share on other sites

most of that code is just for parsing the xml..and turning it into an array...then writing it to a DB.

 

It seems like the response it looking for a parameter named "s", but I don't see how I name the "response". Seems like the return is unnamed, when it should be in the form of a parameter.

 

I am also wondering if this matters, since the values are being written to the DB, it's just the response that is not being recognized.

 

There is prolly a simple answer I am overlooking somewhere.

 

Thanks again in advance.

 

James

Link to comment
https://forums.phpfreaks.com/topic/166726-php-and-soap/#findComment-879187
Share on other sites

this is what they gave me to work off of...and Im having a hard time relating this to the actual code of writing the response. All I can think of its that they are maybe expecting an additional function called DeleteProducts, and since I dont have that yet...I am getting the error...

 

<?xml version='1.0' encoding='UTF-8'?>
<wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.kosmoscart.com/demo/ws/RMSConfirmWS.php" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="http://www.kosmoscart.com/demo/ws/RMSConfirmWS.php" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://www.kosmoscart.com/demo/ws/RMSConfirmWS.php">
<s:element name="ImportRMSProducts">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="xmlStr" type="s:string" />
</s:sequence>
</s:complexType>

</s:element>
<s:element name="ImportRMSProductsResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="ImportRMSProductsResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="DeleteProducts">

<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="xmlStr" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="DeleteProductsResponse">
<s:complexType>
<s:sequence>

<s:element minOccurs="0" maxOccurs="1" name="DeleteProductsResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="string" nillable="true" type="s:string" />
</s:schema>
</wsdl:types>
<wsdl:message name="ImportRMSProductsSoapIn">
<wsdl:part name="parameters" element="tns:ImportRMSProducts" />

</wsdl:message>
<wsdl:message name="ImportRMSProductsSoapOut">
<wsdl:part name="parameters" element="tns:ImportRMSProductsResponse" />
</wsdl:message>
<wsdl:message name="DeleteProductsSoapIn">
<wsdl:part name="parameters" element="tns:DeleteProducts" />
</wsdl:message>
<wsdl:message name="DeleteProductsSoapOut">
<wsdl:part name="parameters" element="tns:DeleteProductsResponse" />

</wsdl:message>
<wsdl:message name="ImportRMSProductsHttpGetIn">
<wsdl:part name="xmlStr" type="s:string" />
</wsdl:message>
<wsdl:message name="ImportRMSProductsHttpGetOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:message name="DeleteProductsHttpGetIn">
<wsdl:part name="xmlStr" type="s:string" />

</wsdl:message>
<wsdl:message name="DeleteProductsHttpGetOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:message name="ImportRMSProductsHttpPostIn">
<wsdl:part name="xmlStr" type="s:string" />
</wsdl:message>
<wsdl:message name="ImportRMSProductsHttpPostOut">
<wsdl:part name="Body" element="tns:string" />

</wsdl:message>
<wsdl:message name="DeleteProductsHttpPostIn">
<wsdl:part name="xmlStr" type="s:string" />
</wsdl:message>
<wsdl:message name="DeleteProductsHttpPostOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:portType name="RMSConfirmWSSoap">
<wsdl:operation name="ImportRMSProducts">

<wsdl:input message="tns:ImportRMSProductsSoapIn" />
<wsdl:output message="tns:ImportRMSProductsSoapOut" />
</wsdl:operation>
<wsdl:operation name="DeleteProducts">
<documentation xmlns="http://schemas.xmlsoap.org/wsdl/">This method would accept product codes of the products that need to be deleted from the database and SKU codes if the inventory on certain items needs to be reset</documentation>
<wsdl:input message="tns:DeleteProductsSoapIn" />
<wsdl:output message="tns:DeleteProductsSoapOut" />
</wsdl:operation>

</wsdl:portType>
<wsdl:portType name="RMSConfirmWSHttpGet">
<wsdl:operation name="ImportRMSProducts">
<wsdl:input message="tns:ImportRMSProductsHttpGetIn" />
<wsdl:output message="tns:ImportRMSProductsHttpGetOut" />
</wsdl:operation>
<wsdl:operation name="DeleteProducts">
<documentation xmlns="http://schemas.xmlsoap.org/wsdl/">This method would accept product codes of the products that need to be deleted from the database and SKU codes if the inventory on certain items needs to be reset</documentation>

<wsdl:input message="tns:DeleteProductsHttpGetIn" />
<wsdl:output message="tns:DeleteProductsHttpGetOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="RMSConfirmWSHttpPost">
<wsdl:operation name="ImportRMSProducts">
<wsdl:input message="tns:ImportRMSProductsHttpPostIn" />
<wsdl:output message="tns:ImportRMSProductsHttpPostOut" />
</wsdl:operation>

<wsdl:operation name="DeleteProducts">
<documentation xmlns="http://schemas.xmlsoap.org/wsdl/">This method would accept product codes of the products that need to be deleted from the database and SKU codes if the inventory on certain items needs to be reset</documentation>
<wsdl:input message="tns:DeleteProductsHttpPostIn" />
<wsdl:output message="tns:DeleteProductsHttpPostOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="RMSConfirmWSSoap" type="tns:RMSConfirmWSSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />

<wsdl:operation name="ImportRMSProducts">
<soap:operation soapAction="http://www.kosmoscart.com/demo/ws/RMSConfirmWS.php" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>

<wsdl:operation name="DeleteProducts">
<soap:operation soapAction="http://www.kosmoscart.com/demo/ws/RMSConfirmWS.php" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>

</wsdl:binding>
<wsdl:binding name="RMSConfirmWSHttpGet" type="tns:RMSConfirmWSHttpGet">
<http:binding verb="GET" />
<wsdl:operation name="ImportRMSProducts">
<http:operation location="/ImportRMSProducts" />
<wsdl:input>
<http:urlEncoded />
</wsdl:input>
<wsdl:output>

<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="DeleteProducts">
<http:operation location="/DeleteProducts" />
<wsdl:input>
<http:urlEncoded />
</wsdl:input>
<wsdl:output>

<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="RMSConfirmWSHttpPost" type="tns:RMSConfirmWSHttpPost">
<http:binding verb="POST" />
<wsdl:operation name="ImportRMSProducts">
<http:operation location="/ImportRMSProducts" />
<wsdl:input>

<mime:content type="application/x-www-form-urlencoded" />
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="DeleteProducts">
<http:operation location="/DeleteProducts" />
<wsdl:input>

<mime:content type="application/x-www-form-urlencoded" />
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="RMSConfirmWS">
<wsdl:port name="RMSConfirmWSSoap" binding="tns:RMSConfirmWSSoap">

<soap:address location="http://www.kosmoscart.com/demo/ws/RMSConfirmWS.php" />
</wsdl:port>
<wsdl:port name="RMSConfirmWSHttpGet" binding="tns:RMSConfirmWSHttpGet">
<http:address location="http://www.kosmoscart.com/demo/ws/RMSConfirmWS.php" />
</wsdl:port>
<wsdl:port name="RMSConfirmWSHttpPost" binding="tns:RMSConfirmWSHttpPost">
<http:address location="http://www.kosmoscart.com/demo/ws/RMSConfirmWS.php" />
</wsdl:port>
</wsdl:service>

</wsdl:definitions>

 

 

Link to comment
https://forums.phpfreaks.com/topic/166726-php-and-soap/#findComment-879205
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.