June 24, 2011

Connect a web service in a php page

Connect a web service in a php page

Connect a web service in a php page instantly lighten the SOAP in our mind as a first word when we talk about web service in php. In simple words if i explain it to you that how can you call this service or connect this service in your php page so you have to make it clear in your mind that you are communicating to a server. When you are communicating to a website or a server, being on web you have to follow the standards and for our convenience a language is introduced which we call XML. So one thing should be clear that response can or will come in XML format. Now, we have to check that what type of structure will that server follow, so it depends upon that query which you are sending as a request.
I am quoting a couple of examples here:

  1. http://www.centrina.com.br/WSConsumoPortal/Service.asmx?op=getListaImoveis
  2. http://www.centrina.com.br/WSConsumoPortal/Service.asmx?op=getFotos

one of them is getting list of movies and other one is getting fotos.
But the difference comes here when we call these URLs or methods differentiate that how we send requests to the server. So the answer is:

PHP Function: SoapClient

The SoapClient class provides a client for » SOAP 1.1, » SOAP 1.2 servers. It can be used in WSDL or non-WSDL mode.

Implementation Example:

$client = new SoapClient(“http://www.centrina.com.br/WSConsumoPortal/Service.asmx?op=getListaImoveis”);

$result = $client-> //here you have to call your desired section from retrieved version of document.

Tip:

As we got server response in $client so now you can go as much depth as you want by following the pointer ->1st->2nd->3rd level of depth.

I hope that you will like the article connect a web service in a php page. As i have written to just to give a little introduction about SoapClient. I will further write it in details, for beginners it is enough to get rid of fear of SOAP, i hope.
Last updated: March 19, 2014
Did it helped? 4 thoughts on “Connect a web service in a php page
  1. James

    I am not aware about the response in XML but heard about response in HTML format

    1. admin Post author

      If i am understanding your confusion correctly so the answer is:
      HTML is the final shape in which we render the data we received from various resources including XML.
      And response in XML means that response in XML format, then it can be rendered in HTML but if you are talking about AJAX based response in which we send HTML in response so that is another story. Response still will be either in JSON, responseText or XML nodes.

      Must share your views, it can be possible that i missed something or not reviewed yet.

  2. Homologous Chromosomes

    I’m still learning from you, as I’m trying to reach my goals. I definitely love reading everything that is written on your site.Keep the stories coming. I enjoyed it!

  3. John

    Thanks, please share your more experience here regarding Web Service.

Comments are closed.