We are trying to interact with a SOAP server written in .NET. One of the parameters for one of the calls is a serialised, base64 encoded .NET object:
<parameter>base64Binary</parameter>
Although I do know the rough make up of the .NET object, I’m at a loss of how to serialise a PHP array/object appropriately for the SOAP server to handle. Obviously PHP and .NET’s serialisation methods are not the same so it’s not going to be as simple as that. The .NET object is also quite complex and is made up of a number of child objects to make things more fun. We have no control over the .NET code either.
Does anyone have any advice on how to handle such a scenario?
Related
I have searched and everything I get looks to be about a PHP app consuming an .aspx web service but that's not what I'm looking for.
I may be overlooking something obvious and would be happy to hear that but that doesn't mean I haven't tried.
I'm a .Net developer by platform, a developer by trade 20+ years and will admit that I'm spoiled by the ease of .Net
That said, an ASP.Net .asmx web service is quite literally a single file that might be pure soap (but it's so well hidden that I don't know) but I can use them with jQuery AJAX calls effortlessly. Methods exist that have parameters (basic types or complex objects defined by classes in my project) and I can call those methods at a single url, pass in my JSON and .Net gives me an object to work with. I do what I need, then return an object matching the methods return type and all the HTTP/JSON/ENCODING/DECODING is done for me so I only need to worry about the JSON client-side, working with my classes server side, and treating the methods like any other server-side method.
Does a library/framework exist for PHP that provides that same sort of ease? From my reading, I think that 'routing' is a related concept but that term isn't one I know in the .Net context so assume I know nothing but basic PHP skills (nothing but server side syntax, operators, data types, etc..)
I want to learn to love PHP but this could be make/break for me because everything I do now ends up being client-side JS/DOM and server-side data management. Very little use for actually manipulating the HTML returned to the client (Call it Google-style web apps).
If it helps define what I'm looking for, I use Telerik Kendo DataSource a lot and need the easiest way to focus on my client-side code with Kendo and actual business logic/db server-side.
Slimframework.com looks to be the closest thing I've found so far but it's not clear to me if it's intended for what I'm needing or if it's perhaps just a common tool that would help get me there. I'm hoping for something clearly more complete.
Just building a new site, we will be building a .net soap service to supply the data to a php site.
I used a fair amount of .net soap services in php, some of which you need to map classes and some that you just provide an array of php data to the service.
Our .net developer has only ever built soap services with class mapping, I would prefer it if we just had to supply a simple array of data to the service. As it will mean making changes will be a lot simpler.
What needs to be enabled on the .net side to allow this, and what are the benefits / pit falls of doing so?
PHP as the Soap client will best work if a WSDL ressource is provided, but apart from that, no further classes are needed - you can use any construct of arrays and/or stdClass objects for the parameters.
But it will make life a lot easier if you use the classmap feature of the SoapClient, e.g. your IDE would complete the names of properties for you, and when debugging you know which part of the object you are dealing with. But it is entirely optional.
The server part has nothing to do with it. But be aware that using the more fancy stuff in SOAP might make it a lot harder for PHP to be the client. If you want this to be easy going, I'd stay away from more complicated structures like XML attributes.
In a response, <element>value</element> will be fine, <element attrib="value"/> might not. But don't take my word for it, I'm just using Java Soap services a lot in PHP, and we don't have attributes.
as from Title.
Possible? Yes, everything is possible :)
But it is sensible? Hardly, it is too Python specific, I'm afraid, and therefore it would not be any fun to write a parser for Python data structures in PHP.
If you really need to do this, then I would recommend building a middle-layer in Python, which would then expose your ZODB over an interface that is usable in PHP. One possiblity would be using HTTP for the protocol and then JSON, XML or whatever else your heart desires for payload.
you could call the XML-RPC interface methods from PHP
I am trying to make a decision whether I should use a REST service or a SOAP service for some web facing functions that I am producing. This decision is based on whether I can easily use the REST service in implementation. I would prefer to use REST, though I don't want to spend days coding the object model in PHP.
The services are being developed in .NET but will be consumed mainly by PHP.
Basically it has come down to one point: Ease of integration. Using SOAP in PHP I can use the NuSOAP library, which will generate the object model.
However with REST I cannot seem to find a way to easily generate that model, if this is possible I would use REST services as they are easier to document and extend, and also have the JSON abilities as well.
Can I generate an object model in PHP from an XML file/schema that I could then serialize with the REST service?
You might not even have to go the class route. Simply ingest the data using simplexml and then traverse it as if it were an object. Or if you have json, json_decode($data, TRUE) would do the same thing (without attributes in brackets).
$ch = curl_init("http://example.com/some/rest/endpoint");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$data = curl_exec($ch);
$obj = simplexml_load_string($data);
print $obj->some->data->you['need'];
That would print here if your XML was something like
<_>
<some>
<data>
<you need="here" />
</data>
</some>
</_>
I had some trouble getting SOAP to work between diffent languages (PHP <> JAVA and PHP <> .NET)
If your going with SOAP, you might want to check out WS-I (Web Services Interoperability)
Based on your described requirements you should stick in the SOAP world. Remember, REST is just a style of architecting a distributed interface. It says nothing about how the functionality of that interface is implemented. There certainly is no need for mapping schemas to objects.
Having said that, if you look at the client tools in the WCF REST Starter kit you will find functionality to paste XML as a CLR type. This will do a best guess at creating a serializable class based on an XML instance document.
Also, from what you are describing ADO.NET Data Services would provide you a quick way of exposing RESTful data services to your PHP site.
....
Here is a question for you? If the .Net services are going to be consumed by a PHP site then why would you describe the .Net services as "web facing". From your description, these services sound more like a private implementation detail of your web site.
If I were you I would:
investigate if NuSOAP tools can be used on just XSD. In the .NET world, you have svcutil (or in the ASMX days, wsdl.exe) to digest .wsdl files to produce proxy classes. But if you have only .xsd files, you can use the xsd.exe tool, or the "aftermarket" XsdObjectGen, which is like a supercharged xsd.exe. Are there similar tools in NuSOAP to do the same? Maybe this is obvious and you've already done it.
if that doesn't pan out, produce a dummy WSDL, and stuff the XSD you have into it. Then, process the .wsdl file with the NuSOAP tools. Grab the generated code, and remove the soap envelope and communications stuff, but retain the object serialization stuff. Not sure if this is possible, the way the PHP (or is it C?) code is generated by the NuSOAP tools. In .NET, it's easy to break the different pieces out.
The whole idea behind rest is that you do not use it with hackish "object models" like with SOAP. The problem is you're trying to use the system wrong :)
If you want object models, use SOAP.
If you want web-friendly APIs, use REST.
For ease of integration, I'd go with a REST API. Since there is such a strong convention, integrating should be relatively straightforward for anybody's who's worked with REST before.
So i think this could be something that i am looking for. but i would like to know if there is some sort of automation system out there for it
found it at http://devzone.zend.com/article/1713#Heading11
Extending Classes
While the above examples were all
doable with PHP 4 and the domxml
extension (only the API was a little
bit different), the ability to extend
DOM classes with your own code is a
new feature of PHP 5. This makes it
possible to write more readable code.
Here's the whole example again,
re-written to use the DomDocument
class:
class Articles extends DomDocument {
function __construct() {
//has to be called!
parent::__construct();
}
function addArticle($title) {
$item = $this->createElement("item");
$titlespace = $this->createElement("title");
$titletext = $this->createTextNode($title);
$titlespace->appendChild($titletext);
$item->appendChild($titlespace);
$this->documentElement->appendChild($item);
} } $dom = new Articles(); $dom->load("articles.xml");
$dom->addArticle("XML in PHP5"); print
$dom->save("newfile.xml");
i am new to flex development my question is How do i pass variables between flex 3 and a mysql database using php? i was told the best way is to AMFPHP but that seems like an over kill or may be not am not sure.. any ideas?
I'd use json over xml since json will transfer less bytes and php's json_encode($object) is quick and easy.
I'd use json over amfphp because json is general purpose. For example, I can create a web service for flex or javascript by returning json.
You might have a look at this article for comparison between json, amfphp, and xml. Also, here is a nice tutorial on flex, php, and json.
AMFPHP is not really being actively developed. The best alternative right now is to use Zend_Amf http://wadearnold.com/blog/?page_id=155, which is supported by both Zend and Adobe.
Don't be scared by the need for Zend Framework components. The framework is modular, and you can use your own custom php classes for accessing data without having to incur the Zend Framework learning curve.
The great thing about using AMF is that since it is a binary data transfer, it's very fast.
Also, working with XML or even JSON, is an annoying extra step if you just want your flex app to get results data an api call. If, for some reason, you need to also handle outputting data to xml or json, that can easily be added to your app by extending or creating new controllers/services that translate the data from arrays and objects to xml or json
There's a few choices open to you. Essentially, it boils down to how you'd like to deal with the data on the PHP side of the fence.
The two I'd spend time investigating would be simple XML (my first preference) and AMFPHP.
XML:
Flex can work very easily with XML data, even mapping it automatically to/from ActionScript objects (generically, or with something like the xobj project on GoogleCode, to typed instances). Similarly, there's plenty of support available for working with XML in PHP code.
AMFPHP:
AMFPHP gives you way to pass typed ActionScript objects over the wire to your PHP code. There's tooling included in the AMFPHP project that makes working with MySQL on the PHP side easy too.
If you are doing a simple query, I would pass your data as plain POST data. You can do this using HTTPService component in Flex. On the PHP side I would respond with an XML string and set the HTTPService resultFormat to "e4x" (Ecmascript for XML), for an easy object-like manipulation of the result data.
Here is the livedocs reference for HTTPService: http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_2.html
For more complicated queries/operations, there is also the option of using the Flex RemoteObject with AMF as the data protocol. On the PHP side you can then use the zend framework AMF component to communicate.
Here is the livedocs reference for RemoteObject: http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_4.html
And the download page for Zend AMF: http://framework.zend.com/download/amf