Reputation: 11612
I have one web service created in asp.net and published in iis 5.1 .Now i want to call this web service from php environment. Actually my web service get one string as a parameter and return the same string .But all the time, the returned string is empty or null.I could not able to send string value from php to asp.net web service...
This is my web service created in asp.net
namespace PRS_WS
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class prs_point : System.Web.Services.WebService
{
[WebMethod]
public string testAssignment(string inputData)
{
return inputData;
}
}
}
And, this is my php code for calling the above asp.net web service...
<?php
require_once('nusoap/lib/nusoap.php');
$wsdl="http://localhost/prs_point/prs_point.asmx?WSDL";
$str1="";
$str1="Hello from php";
$client = new soapclient($wsdl,'wsdl');
$result=$client->call('testAssignment',$str1);
foreach($result as $key => $value)
{
echo "<br/>Response ::::: $value";
}
?>
I don't know whether the changes needed in php side or asp.net side?...Please guide me to get out of this issue...
Upvotes: 2
Views: 17931
Reputation: 11612
This code is working fine for me...
<?php
require 'nusoap/lib/nusoap.php';
$client = new nusoap_client('http://localhost/prs_point/prs_point.asmx?WSDL', 'WSDL');
$error = $client->getError();
if ($error) {
die("client construction error: {$error}\n");
}
$param = array('inputData' => 'sample data');
$answer = $client->call('testAssignment', array('parameters' => $param), '', '', false, true);
$error = $client->getError();
if ($error) {
print_r($client->response);
print_r($client->getDebug());
die();
}
print_r($answer);
?>
Upvotes: 6
Reputation: 1975
You would be better off defining your service in WCF, this gives you more control over the generated SOAP, and while I'm not sure about PHP, I have had issues in the past getting ASMX web services to work with Adobe Flex so integration isn't always seemless despite the fact it still uses the SOAP protocol. Besides that your service looks fine but I don't think you need these lines:
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
from the PHP side, you should be able to call $result = $client -> testAssignment( $str1 );
but (I've forgotten) you may need to access the result value $result = $client -> testAssignment( $str1 ) -> testAssignmentResult;
you also have to pass parameters to the methods bundled in arrays instead of calling with multiple arguments, see this article for a full example.
HTH
Upvotes: 0
Reputation: 563
try this.
$client = new SoapClient("http://localhost/prs_point/prs_point.asmx?WSDL");
$params->inputData= 'Hello';
$result = $client->testAssignment($params)->testAssignmentResult;
echo $result;
Upvotes: 0