I want to execute remote function by using php soap.The web service is created by using c# .net.There must be authentication in order to call remote function.I always get unauthorized error whenever i tried to call remote function.However,when i get content of web service by using wget like this
wget -c --user=my_username --password=my_password http://path/to/wsdl
and i got this output:
--2011-02-09 09:55:10-- http://path/to/wsdl
Connecting to my_ip:80... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Reusing existing connection to my_ip:80.
HTTP request sent, awaiting response... 401 Unauthorized
Reusing existing connection to my_ip:80.
HTTP request sent, awaiting response... 200 OK
Length: 3300 (3.2K) [text/html]
Saving to: `my_webservice.asmx'
100%[====================================================================================================================================================================================================>] 3,300 --.-K/s in 0.001s
2011-02-09 09:55:11 (3.81 MB/s) - `my_webservice.asmx' saved [3300/3300]
When i use soap inorder to call remote function like this:
$connSoap = new SoapClient($WebServiceUrl, array('login' => $username,
'password' => $password));
$requestOutput = $connSoap->GetVal (1, 1, 1);
I got this error:
SoapClient::SoapClient(http://path/to/wsdl): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized
Any comments?
Th开发者_开发问答anks in advance
I have found alternative way to do solve this problem
I prepared and envelope xml and send request by using curl that has envelope as parameter.You can refer following code;
$username = "";
$password = "";
$webServiceUrl = "";
$xml = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<RemoteMethod xmlns="http://your.service.url/">
<parameter_1>your_paramter_1</parameter_1>
<parameter_2>your_paramter_2</parameter_2>
........
<parameter_n>your_parameter_n</parameter_n>
</RemoteMethod>
</soap:Body>
</soap:Envelope>';
$ch = fopen("envelope.xml", "w");
fwrite($ch, $xml);
$cmd = 'curl -d @envelope.xml -H "Content-Type: text/xml;charset=UTF-8 " --user ' . $username . ':'.$password.' --ntlm ' . $webServiceUrl . ' > requestResult.xml';
shell_exec($cmd);
fclose($ch);
精彩评论