I'm trying to call an AspNet WebService (C# 3.5) from PHP (5.3.5) using NuSoap.
<?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'] : '';
$client = new nusoap_client("http://localhost:53096/MyWebService.asmx?wsdl", 'wsdl', $proxyhost, $proxyport, $proxyusername, $proxypassword);
$callParams= array(
'token' => "Token"
, 'ppp' => array(1,2,3)
);
$result = $client->call("MyWebMethod", $callParams);
?>
My WebMethod is very simple:
[WebMethod()]
public int[] MyWebMethod(string token, int[] ppp)
{
return ppp;
}
When I set a breakpoint in VisualStudio 2008, token is OK but ppp = empty array of int (not null).
Any idea of what is wrong with my code?
i don't know about nusoap, but the native PHP SoapClient class has a method to dump out the last XML request sent to the web service, this is probably a good place to start
If the second parameter name is callParams, then you should use the same name while calling method from php (not 'ppp').
Related
Hi developers i am new to web services i wrote a simple php web service but i got 'Empty Xml'.
Here is my php code.
<?php
require_once ('lib/nusoap.php');
$server = new soap_server;
$server->configureWSDL('SimpleWebService', 'urn:http://webservicesoap/server.php');
$server->register("test", array('your_name' => 'xsd:string'), array('return' =>
'xsd:string'), "http://webservicesoap/server.php", false, 'rpc', 'encoded',
'Simple Add Function');
function test($your_name)
{
if (!$your_name)
{
return new SoapFault('Client', '', 'Put Your Name!');
}
$result = "Welcome to " . $your_name .
". Thanks for Your First Web Service Using PHP With SOAP";
return $result;
}
$HTTP_POST_RAW_DATA = isset($HTTP_POST_RAW_DATA) ? $HTTP_POST_RAW_DATA : '';
$server->service($HTTP_POST_RAW_DATA);
exit();
?>
Here is C# code.
Test.SimpleWebService t = new Test.SimpleWebService();
t.test("Jawad Zeb");
Note: I have added the web refference and also wamp server is running.
Please help me solving this problem. Any help is appreciated.
Here is the screenshot of exception.
i am connecting to webservice using php.
try {
$client = new SoapClient("https://.....",array(
'exceptions' => true
));
} catch ( SoapFault $e ) {
echo 'sorry... our service is down';
}
in c# it is working, while in binding for that is set allowCookies="true".
how and where should i add this allowCookies="true", if i want to use php soap client?
thank you.
You should use SoapClient::__setCookie()
I am trying to use WDSL SOAP in PHP. The initial connection seems to work fine but I am struggling to 'convert' some C# to PHP, in particular headers.
AreaSearchRequest request = new AreaSearchRequest();
request.GUID = "1234";
request.Location = "UK";
// Create AreaSearchHeader, assign AreaSearchRequest
AreaSearchHeader header = new AreaSearchHeader();
header.Request = request;
header.Validate = false;
// SOAP connection
soap.Open();
// Call the AreaSearch method response object
AreaSearchResponse response = soap.AreaSearch(header);
//Close API connection
soap.Close();
And here is my rough translation into PHP.
$wsdl = "https://whatever/";
$options = array(
'trace' => 1,
);
$client = new SoapClient($wsdl, $options);
$request = array(
'GUID' => '1234',
'Location' => 'UK',
);
$client->__soapCall('AreaSearch', $request);
What is really throwing me off is the header stuff to make a valid request! Thanks (sorry, I have no experience of C# whatsoever).
try using nusoap https://sourceforge.net/projects/nusoap/ to do the heavy lifting. I dont use PHP myself but a have a load of c# soap services that people I work with use nusoap to consume and they haven't had any issues
I got a WCF service with a method to receive files, looking something like this
public bool UploadFile(string fileName, byte[] data)
{
//...
}
What I'd like to do is to post the data to this method in the WCF service from PHP, but are unaware if it's even possible to post byte arrays from PHP to a .NET method hosted by a WCF service.
So I was thinking of something like this
$file = file_get_contents($_FILES['Filedata']['tmp_name']); // get the file content
$client = new SoapClient('http://localhost:8000/service?wsdl');
$params = array(
'fileName' => 'whatever',
'data' => $file
);
$client->UploadFile($params);
Would this be possible or are there any general recommendations out there I should know about?
Figured it out.
The official php documentation tells that the file_get_contents returns the entire file as a string (http://php.net/manual/en/function.file-get-contents.php). What noone tells is that this string is compatible with the .NET bytearray when posted to a WCF service.
See example below.
$filename = $_FILES["file"]["name"];
$byteArr = file_get_contents($_FILES['file']['tmp_name']);
try {
$wsdloptions = array(
'soap_version' => constant('WSDL_SOAP_VERSION'),
'exceptions' => constant('WSDL_EXCEPTIONS'),
'trace' => constant('WSDL_TRACE')
);
$client = new SoapClient(constant('DEFAULT_WSDL'), $wsdloptions);
$args = array(
'file' => $filename,
'data' => $byteArr
);
$uploadFile = $client->UploadFile($args)->UploadFileResult;
if($uploadFile == 1)
{
echo "<h3>Success!</h3>";
echo "<p>SharePoint received your file!</p>";
}
else
{
echo "<h3>Darn!</h3>";
echo "<p>SharePoint could not receive your file.</p>";
}
} catch (Exception $exc) {
echo "<h3>Oh darn, something failed!</h3>";
echo "<p>$exc->getTraceAsString()</p>";
}
Cheers!
I try to implement simple SOAP server on ASP.NET and simple client on php and get the problem with response and request format.
My server is very simple, take one string and return another:
[WebMethod]
public string HelloWorld(string Additional) {
return "Hello " + Additional;
}
I expect, that php client is such simple:
$client = new SoapClient('path');
print_r($client->HelloWorld('homm'));
Hello homm
But actually, function take only objects and return object with single member — HelloWorldResult:
$client = new SoapClient('path');
print_r($client->HelloWorld(array('Additional' => 'homm')));
stdClass Object
(
[HelloWorldResult] => Hello homm
)
Can I change this behavior? What part I need to change, server (ASP.NET) or client(php) to work with results and parameters indirect?