0

Ok my .net 4.0 client works fine. People using java all have no issues. But when it comes to php our php developer cant get anything to work.

Now keep in mind i did not create a Wcflibray project, i created a regular asp 4.0 website and then added a WCF Service so i do not have a app.config, i have a web.config.

We have went down to the bare essentials of creating two methods

string HelloWorld()
{
return "Hello!";
}

and

string HellowTomorrow(string sret)
{
return sret;
}

In debug mode i will see him enter my method but only with null. If i packet sniff with wireshark, he is not passing the paramater envelope.

I have googled endlessly but all examples are from a WCF service project, not a website that has added a WCF Service too it. (rememember, everyone else is having no problems, java, .net 2.0, etc)

Here is his php 5.3

error_reporting(E_ALL);

ini_set('display_errors','On');

$client = new SoapClient("http://99-mxl9461k9f:6062/DynamicWCFService.svc?wsdl", array('soap_version' => SOAP_1_1));

$client->soap_defencoding = 'UTF-8';


//$args = array('john');


$args = array('param1'=>'john');


$webService = $client->__soapCall('HelloTomorrow',$args);


//$webService = $client->HelloTomorrow($args); 


var_dumpp($webService); 


?>
hakre
  • 193,403
  • 52
  • 435
  • 836
MichaelEvanchik
  • 1,748
  • 1
  • 13
  • 23
  • 2
    Which binding are you using for your WCF service? I see that your PHP client uses SOAP 1.1 and in WCF only basicHttpBinding will be compatible with this standard. – dmusial Apr 25 '12 at 19:56
  • as for the binding question, how can i really tell? its not defined in my wsdl, or web.config or code. all is what you see is above. – MichaelEvanchik Apr 26 '12 at 14:06
  • here is the web.config – MichaelEvanchik Apr 26 '12 at 14:07
  • and here is a working .net 4.0 client app.cofig – MichaelEvanchik Apr 26 '12 at 14:11
  • Error HTTP Error: Unsupported HTTP response status 415 Cannot process the message because the content type 'text/xml; charset=ISO-8859-1' was not the expected type 'text/xml; charset=utf-8'. (soapclient->response has contents of the response) Request POST /DynamicWCFService.svc HTTP/1.0 Host: 99-mxl9461k9f:6062 User-Agent: NuSOAP/0.9.5 (1.123) Content-Type: text/xml; charset=ISO-8859-1 SOAPAction: "http://tempuri.org/IDynamicWCFService/HelloTomorrow" Content-Length: 389 is the issue changing the charset – MichaelEvanchik Apr 26 '12 at 14:24
  • I'm pretty sure that WCF will enforce that the charset matches, so that is probably your issue, based on that error message. Not sure how to fix that from php though... – CodingWithSpike Apr 27 '12 at 00:38
  • I've never used NuSOAP, but try `$client->decodeUTF8(false);` after `$client->soap_defencoding = 'UTF-8';` – Joel C Apr 27 '12 at 03:35
  • If that doesn't work, try using the PHP SoapClient instead of the NuSOAP version (see my updated answer below). – Joel C Apr 27 '12 at 03:59

2 Answers2

1

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:

  1. Check the binding in your web.config file. It has to be “basicHttpBinding” for PHP
  2. PHP, $client->__soapCall() 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.
  3. If required then pass “array('soap_version' => SOAP_1_1)” or “array('soap_version' => SOAP_1_2)” to SoapClient() object to explicitly declare soap version.
  4. Always try declaring “array( "trace" => 1 )” to SoapClient Object to read the Request & Response strings.
  5. Use “__getLastResponse();” function to read Response String.
  6. Use “__getLastRequest();” function to read Request String.

IMPORTANT:If you are getting NULL return for any value passed as parameter then check your .cs(.net) file that look like this:

   [ServiceContract]
    public interface IDynamicWCFService
    {
        [OperationContract]
        string HelloYesterday(string test);
    }

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.

Example #1: using php-soap with single parameter for HelloYesterday function

<?php
$url="http://99-mxl9461k9f:6062/DynamicWCFService.svc?WSDL";
$client = new SoapClient($url, array( "trace" => 1 ));
$result = $client->HelloYesterday(array('test' => 'this is a string'));
var_dump($result);
$respXML = $client->__getLastResponse();
$requXML = $client->__getLastRequest();
echo "Request: <br>";
var_dump($requXML);
echo "Response: <br>";
var_dump($respXML);
?>

Example #2 : using nusoap with single parameter for HelloYesterday function

<?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->soap_defencoding = 'UTF-8'; // this is only if you get error of soap encoding mismatch.
$err = $client->getError();
if ($err) {
    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
// Doc/lit parameters get wrapped
$param = array('test' => ' This is a string for nusoap');
$result = $client->call('HelloYesterday', array('parameters' => $param), '', '', false, true);
// Check for a fault
if ($client->fault) {
    echo '<h2>Fault</h2><pre>';
    print_r($result);
    echo '</pre>';
} else {
    // Check for errors
    $err = $client->getError();
    if ($err) {
        // Display the error
        echo '<h2>Error</h2><pre>' . $err . '</pre>';
    } else {
        // Display the result
        echo '<h2>Result</h2><pre>';
        print_r($result);
        echo '</pre>';
    }
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>

One more example… passing array as a parameter or pass mixed type parameter then check the following example:

Example #3: passing mixed type parameter including array parameter to Soap function. Example of .net operation file

   [ServiceContract]
    public interface IDynamicWCFService
    {
        [OperationContract]
        string[] HelloYesterday (string[] testA, string testB, int testC );
    }

PHP code

<?php
$url="http://99-mxl9461k9f:6062/DynamicWCFService.svc?WSDL";
$client = new SoapClient($url, array( "trace" => 1 ));
$params = array(
"testA" => array(0=>"Value1",1=>"Value2",2=>"Value3"),
"testB" => “this is string abc”,
"testC" =>123
); // consider the first parameter is an array, and other parameters are string & int type.
$result = $client->GetData($params); 
var_dump($result);
$respXML = $client->__getLastResponse();
$requXML = $client->__getLastRequest();
echo "Request: <br>";
var_dump($requXML);
echo "Response: <br>";
var_dump($respXML);
?>

Hope the above examples will help.

swtweb
  • 46
  • 6
0

Since you're passing the wsdl location into the SoapClient constructor, you should be able to call $client->HelloTomorrow($args). There seem to be a few typos, though, can you verify that they are all correct in your actual code? In your web service code, you name the function HellowTomorrow but you're calling HelloTomorrow in your PHP code. Also, the parameter is named sret in your web service, but it's being passed as param1 in the $args associative array. Does it work calling HelloWorld() which doesn't expect any parameters?

Update: See NuSOAP and content type

Try using the built-in PHP SoapClient instead of the NuSOAP version. PHP's SoapClient looks like it defaults to UTF-8, where NuSOAP seems to be hard-coded to ISO-8859-1

Community
  • 1
  • 1
Joel C
  • 5,547
  • 1
  • 21
  • 31
  • fyi ignore the typo, thats all it is, and the php developer said he tried what you suggested already as well. anyone else have any ideas? – MichaelEvanchik Apr 26 '12 at 14:04
  • I actually changed in web config to iso-8859-1 get no errors, but when you look at the soap xml envelope the parmater is blank but the evenloper is formated correctly – MichaelEvanchik Apr 27 '12 at 17:16