soapclient request from php to c# web service with authentication -
i want execute remote function using php soap.the web service created using c# .net.there must authentication in order call remote function.i unauthorized error whenever tried call remote function.however,when content of web service using wget this
wget -c --user=my_username --password=my_password http://path/to/wsdl
and got output:
--2011-02-09 09:55:10-- http://path/to/wsdl connecting my_ip:80... connected. http request sent, awaiting response... 401 unauthorized reusing existing connection my_ip:80. http request sent, awaiting response... 401 unauthorized reusing existing connection 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 use soap inorder call remote function this:
$connsoap = new soapclient($webserviceurl, array('login' => $username, 'password' => $password)); $requestoutput = $connsoap->getval (1, 1, 1);
i got error:
soapclient::soapclient(http://path/to/wsdl): failed open stream: http request failed! http/1.1 401 unauthorized
any comments?
thanks in advance
i have found alternative way solve problem
i prepared , envelope xml , send request using curl has envelope 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);
Comments
Post a Comment