Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While working with WCF service .net as Server and PHP-soap as client you need to follow guideline strictly. The documentation of PHP-soap is not enough to debug and not that clear either. PHP nusoap is little better on documentation but still not enough on example and not a great choice for the beginners. There are a few examples for nusoap but most of them don’t work. I would suggest following debug checklist:</p> <ol> <li>Check the binding in your web.config file. It has to be “<strong>basicHttpBinding</strong>” for PHP</li> <li>PHP, <strong>$client->__soapCall()</strong> function sends all arguments as an array so if your web-service function require input parameters as an array then arguments has to be in an extra array. Example#3 is given below to clear.</li> <li>If required then pass “<strong>array('soap_version' => SOAP_1_1)</strong>” or “<strong>array('soap_version' => SOAP_1_2</strong>)” to SoapClient() object to explicitly declare soap version.</li> <li>Always try declaring “array( "trace" => 1 )” to SoapClient Object to read the Request &amp; Response strings.</li> <li>Use “<strong>__getLastResponse();</strong>” function to read Response String.</li> <li>Use “<strong>__getLastRequest();</strong>” function to read Request String.</li> </ol> <p><strong>IMPORTANT:If you are getting NULL return for any value passed as parameter then check your .cs(.net) file that look like this:</strong></p> <pre><code> [ServiceContract] public interface IDynamicWCFService { [OperationContract] string HelloYesterday(string test); } </code></pre> <p>The variable name passes here, have to match with when you call it in PHP. I am taking it as “test” for my examples below.</p> <p><strong>Example #1</strong>: using php-soap with single parameter for HelloYesterday function</p> <pre><code>&lt;?php $url="http://99-mxl9461k9f:6062/DynamicWCFService.svc?WSDL"; $client = new SoapClient($url, array( "trace" =&gt; 1 )); $result = $client-&gt;HelloYesterday(array('test' =&gt; 'this is a string')); var_dump($result); $respXML = $client-&gt;__getLastResponse(); $requXML = $client-&gt;__getLastRequest(); echo "Request: &lt;br&gt;"; var_dump($requXML); echo "Response: &lt;br&gt;"; var_dump($respXML); ?&gt; </code></pre> <p><strong>Example #2</strong> : using nusoap with single parameter for HelloYesterday function</p> <pre><code>&lt;?php require_once('../lib/nusoap.php'); $proxyhost = isset($_POST['proxyhost']) ? $_POST['proxyhost'] : ''; $proxyport = isset($_POST['proxyport']) ? $_POST['proxyport'] : ''; $proxyusername = isset($_POST['proxyusername']) ? $_POST['proxyusername'] : ''; $proxypassword = isset($_POST['proxypassword']) ? $_POST['proxypassword'] : ''; $url="http://99-mxl9461k9f:6062/DynamicWCFService.svc?WSDL"; $client = new nusoap_client($url, 'wsdl', $proxyhost, $proxyport, $proxyusername, $proxypassword); $client-&gt;soap_defencoding = 'UTF-8'; // this is only if you get error of soap encoding mismatch. $err = $client-&gt;getError(); if ($err) { echo '&lt;h2&gt;Constructor error&lt;/h2&gt;&lt;pre&gt;' . $err . '&lt;/pre&gt;'; } // Doc/lit parameters get wrapped $param = array('test' =&gt; ' This is a string for nusoap'); $result = $client-&gt;call('HelloYesterday', array('parameters' =&gt; $param), '', '', false, true); // Check for a fault if ($client-&gt;fault) { echo '&lt;h2&gt;Fault&lt;/h2&gt;&lt;pre&gt;'; print_r($result); echo '&lt;/pre&gt;'; } else { // Check for errors $err = $client-&gt;getError(); if ($err) { // Display the error echo '&lt;h2&gt;Error&lt;/h2&gt;&lt;pre&gt;' . $err . '&lt;/pre&gt;'; } else { // Display the result echo '&lt;h2&gt;Result&lt;/h2&gt;&lt;pre&gt;'; print_r($result); echo '&lt;/pre&gt;'; } } echo '&lt;h2&gt;Request&lt;/h2&gt;&lt;pre&gt;' . htmlspecialchars($client-&gt;request, ENT_QUOTES) . '&lt;/pre&gt;'; echo '&lt;h2&gt;Response&lt;/h2&gt;&lt;pre&gt;' . htmlspecialchars($client-&gt;response, ENT_QUOTES) . '&lt;/pre&gt;'; echo '&lt;h2&gt;Debug&lt;/h2&gt;&lt;pre&gt;' . htmlspecialchars($client-&gt;debug_str, ENT_QUOTES) . '&lt;/pre&gt;'; ?&gt; </code></pre> <p>One more example… passing array as a parameter or pass mixed type parameter then check the following example:</p> <p><strong>Example #3:</strong> passing mixed type parameter including array parameter to Soap function. Example of .net operation file</p> <pre><code> [ServiceContract] public interface IDynamicWCFService { [OperationContract] string[] HelloYesterday (string[] testA, string testB, int testC ); } </code></pre> <p><strong>PHP code</strong></p> <pre><code>&lt;?php $url="http://99-mxl9461k9f:6062/DynamicWCFService.svc?WSDL"; $client = new SoapClient($url, array( "trace" =&gt; 1 )); $params = array( "testA" =&gt; array(0=&gt;"Value1",1=&gt;"Value2",2=&gt;"Value3"), "testB" =&gt; “this is string abc”, "testC" =&gt;123 ); // consider the first parameter is an array, and other parameters are string &amp; int type. $result = $client-&gt;GetData($params); var_dump($result); $respXML = $client-&gt;__getLastResponse(); $requXML = $client-&gt;__getLastRequest(); echo "Request: &lt;br&gt;"; var_dump($requXML); echo "Response: &lt;br&gt;"; var_dump($respXML); ?&gt; </code></pre> <p>Hope the above examples will help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload