开发者

Calling a SOAP web service from PHP

开发者 https://www.devze.com 2023-03-04 20:13 出处:网络
I\'ve never done this before so I\'m completely in the dark. I\'m using PHP and I need to call a SOAP service running on 开发者_开发百科a remote server that responds to a call with a status code. How

I've never done this before so I'm completely in the dark. I'm using PHP and I need to call a SOAP service running on 开发者_开发百科a remote server that responds to a call with a status code. How exactly do I make a call? The service is running on a specific ip/port and it has a name, ie: http://1.2.3.4:1000/ServiceName?1234 where 1234 is a parameter I'm passing and for which I expect an answer from the service.

Please give me a few guidelines, thanks!


Assuming you have allow_url_fopen on (usually true), it may be as simple as...

$response = file_get_contents('http://1.2.3.4:1000/ServiceName?1234');


For very simple request/response sets, you can basically do

 $response = file_get_contents('http://1.2.3.4:1000/ServiceName?1234');

If you need to do anything "special", like authenticate to the server, log in, process cookies, etc... you'd be better off using cURL instead, or look at the streams wrapper stuff.


If this is a SOAP/WSDL-Based web service, you should look into the SoapClient classes as they'll basically do most of the legwork for you.

Otherwise, you can use a basic call to file_get_contents to grab the response of a web service into a string.

This would obviously only work if you're only doing a GET request, for POST and further requirements look into cURL.

0

精彩评论

暂无评论...
验证码 换一张
取 消