Simple SOAP example - php

Hey!
I don't really understand what soap is but it doesn't matter. I need to make some soap site that redirect to normal site or have simple content in it like 'test'.
I will need to acces it by soap:// ---- is it ever possible ?

Never good idea to use something that you classify as "I don't really understand what soap is but it doesn't matter"
http://www.w3schools.com/SOAP/soap_intro.asp
Go through it its quite good and simple
And yea its not possible at least to my knowledge
And if you do not feel like clicking link this might help (from w3schools.com)
What is SOAP?
SOAP stands for Simple Object Access Protocol
SOAP is a communication protocol
SOAP is for communication between applications
SOAP is a format for sending messages
SOAP communicates via Internet
SOAP is platform independent
SOAP is language independent
SOAP is based on XML
SOAP is simple and extensible
SOAP allows you to get around firewalls
SOAP is a W3C recommendation

No it's not really possible. Yes, it does mater if you understand what SOAP is.
You can't redirect from a SOAP "site" to a "normal" site. That's because there are no SOAP "sites". SOAP uses XML that is not able to be parsed by a web browser. The web browser needs to do the redirecting.
If you mean to say that you want a certain URL that runs a SOAP service to redirect web browsers to a different page, then you'll have to look reading the user agent, and giving the appropriate response.
This is in fact a useful and good idea if you are developing a SOAP service, but it doesn't sound like that's what you are doing.

Related

How web-services handle requests and responses, and how PHP could access this correctly?

I'm having troubles to figure out how web services handle requests and send responses, and how my site/module will handle it. So these are my questions and bellow a little about why i am asking this:
What is the right way to send a request to web service?
How a web-service will usually answer a site requesting?
How a PHP site can send a request to a web-service? Is cURL the right way?
I'm a student who are learning PHP and a lot of other things, and my job now is create a Joomla Module to show information from a web service (probably created in java or something, probably created by me, when i learn java...).
I know i will use http requests to talk with the web service, but i worry im using it wrong (making a request to the url, like the browser).
So, i did a little example site and a example API. The api uses Slim microframework to create routes, access my database and return the content in json (what means: if i access 'api.com/api/something' in my browser i see a plain white page with a lot of json). I pretend this is my web service.
The example site send a request to the API with cURL, reads the content and decode the json and do things. It seems forced to me.
I have not much support to understand web services and if i am in the right way (or far from this).
I would appreciate your help.
You are on the right track. A web service is simply a processing or storage facility intended to be accessed by some other program just like a database or fileserver service.
What is the right way to send a request to a web service
It depends. The most common implementations use SOAP or REST which define additional semantics on top of the HTTP protocol. SOAP uses a single URL as a gateway to the service and more specific selection of the functionality and the relevant data is embedded within an XML payload presented via POST. HTTP is merely a bearer for the message exchange. In REST, the HTTP part is integrated into the semantics of the transaction.
The URL identifies the location of the data (or processing function)
The payload contains only data, usually presented as POSTed JSON or XML,
further REST uses the HTTP verb (GET, POST, PUT, DELETE) to indicate the requested action
the HTTP headers are used to convey transaction meta-data.
How a web service will usually answer a request
I'm not sure what you are asking here. It should report back on the state of the request, any relevant error messages and possibly some data.
The speciifics would be unique to the API and documented.
Is cURL the right way?
While it is possible to do a lot with the HTTP wrappers functionality in PHP, libcurl offers an lot more flexibility. So, yes this it would be hard to implement a REST client without using cURL, OTOH a SOAP client is (usually) less complex at the HTTP tier but life is a lot simpler if you use a SOAP library/framework to abstract the more complex protocol.
For future questions please have one question per entry.
What is the right way to send a request to web service?
That really depends on the web service, what they require. It can be as simple as a short text string, to sending a XML formatted or JSON formatted array. You need to research the relevant web service.
How a web-service will usually answer a site requesting?
Again it depends on the web service. They are not the same. A web service will have documentation on what it expects and how it will respond.
How a PHP site can send a request to a web-service? Is cURL the right way?
Curl is a good method and is usually the method used from within PHP.

Difference between cURL and SOAP in PHP?

I am curious to know about different ways of implementing web services in PHP? Is there other ways except cURL and SOAP? How SOAP is different than cURL? Is there any similarities also between them?
Thanks,
ursitesion
You can implement a web service in PHP with SoapServer or with PHP - return JSON creating a REST interface. There are other ways, such as XML-RPC, but I usually end using either SOAP or REST, I prefer REST whenever possible.
Curl is a tool that you can use to consume a web service, it's not used to create a web service.
REST or SOAP reading that might help.
Probably best to think of cURL as just a way to send a request (eg GET,POST) to another server.
There are alternatives to cURL, including just straight file_get_contents()
Edit : replaced a rotted link. Also, having used SOAP quite a lot since this first reply, I'd add that another main reason you'd prefer SOAP to REST would be if you have to absolutely, positively double check that every transaction was received, else have the opportunity to resend it. No doubt you can do this with a suitably designed REST webservice, but that would need careful design and testing.

Raw text SOAP message with PHP

I´m trying to do an integration between my own PHP application, and other external software which is 'waiting for' (listening) SOAP messages. But the key question on my situation is that this software which is listening for SOAP messages only accepts RAW contents and has no method which could be called, or Wsdl to be used.
Yes I know... it´s quite strange because with SOAP you usually should send a method request with some parameters, but in this case the only that I have is a URL where I should send with SOAP message that should contain only an string (formatted in a special way which is not a problem), and then this server will return to my PHP application another SOAP message that will contain a string. And that´s all.
Seems that in my case I can not use a PHP SOAP library because I have no method (or function) to call; the only thing that I have is a URL and a string that I should pass like a parameter. I´ve been thinking of using PHP sockets to create a basic SOAP message to that 'strange soap server', but I have no clue about how to do it, or how I woule create with PHP a way to keep my application waiting for the answer comming from that external server.
Thank you so much for your help in advance.
You might be best of by just making the WSDL on your own. It isn't the most trivial thing to do, but it is well documented so you should be able to figure it out.
THere is no need to get the WSDL from the service you're sinding your requests to (it is rather better to have WSDL locally in some cases), so you just initialize the default SOAP client in PHP with that local WSDL, and off you go.

Create a webservice in Php native

I am new in web service. I was totally confused when seeing examples to create web service in internet. Actually, My client have xml to place the orders. what they want is they need to create a wsdl(web service) to call the xml by their vendor forms. So i need to create a webservice that integrate with xml and vendopform(it may be in any language). How i can do this, my mind has empty now to think this. Can any body help me to sort this issue.
If you're creating a SOAP service (which it sounds like you are, and I feel sorry for you ;)), try starting by looking at PHP's SOAP extension:
http://php.net/manual/en/book.soap.php
If you can create something more RESTful, Ruby on Rails does a good job at allowing you to throw together a quick and dirty web service without too many headaches, but even in PHP you can create RESTful APIs pretty easily.
You can read the HTTP request body via e.g. fgets(STDIN) if your requests will accept XML as a POST/PUT format.
But yes, your question is too broad to provide anything more than nudges towards the tools you might choose to use.

PHP site to post data to ASP.net Webservice

I've got a site running on php and I need my form to post data to an ASP.Net web service. All I have from the ASP.Net web service is a url ending in .svc and then I open up the url I get another link that I can click on which ends in .svc?wdsl
This is all pretty new to me so I'm not sure where to begin, any pointers?
Thanks
The ASP.NET site is exposing a WCF service, and the ?wsdl url you're seeing (pronounced wis-dul) is a XML file which describes all of the functionality provided by the service and the input/output parameters. See the Wikipedia article on Web Services Description Language for more info.
With the small amount of background info, you can find some examples about consuming a WCF service from PHP (the fact that it's a WCF service shouldn't make any difference btw, so any example of consuming a web service should work):
http://weblogs.asp.net/gunnarpeipman/archive/2007/09/17/using-wcf-services-with-php.aspx
http://spacebug.com/php-calling-wcf-part-2-html/
The .svc?wsdl link will give you the WSDL for the web service (which describes which methods are available and what their parameters are).
Once you have the WSDL, you can construct a SoapClient with it and call the methods.
It sounds like you've been given a .NET SOAP Web Service to consume.
Check out the PHP docs for consuming/working with SOAP Services:
PHP: SOAP - Manual (Paying close attention to SoapClient which is what you'll use to actually construct and call the service)
steven,
you'll need to do a refresher on wsdl and webservices under .net.
there are obviously lots of places to look online but certainly if you google: 'asp.net wcf wsdl webservice' you should get plenty of hits to help you along.
jim

Categories