SOAP in Pike?

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

SOAP in Pike?

Stephen R. van den Berg
Has anyone tried doing SOAP queries from Pike?
--
Stephen.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SOAP in Pike?

Pontus Östlund

27 okt. 2016 kl. 20:39 skrev Stephen R. van den Berg <[hidden email]>:

Has anyone tried doing SOAP queries from Pike?


Here are some helper stuff for SOAP:

Maybe it helps, maybe it doesn't :D

# Pontus

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SOAP in Pike?

Stephen R. van den Berg
Pontus ??stlund wrote:
>> Has anyone tried doing SOAP queries from Pike?

>Here are some helper stuff for SOAP:
>https://github.com/poppa/pike-soap-helper <https://github.com/poppa/pike-soap-helper>

It helped.  Even though I originally didn't intend to, I got sidetracked and
implemented something close to a full SOAP-wdsl parser.
I'm currently determining what the most appropriate sync and/or async interface
to Pike would be.
I now have a working sync-interface that allows things like this:

  SoapClient soap;
  mapping args, sh, th;

  soap = SoapClient("https://api.affili.net/V2.0/PublisherProgram.svc?wsdl");
  args = soap->getarguments("GetPrograms");
  sh = args->GetProgramsRequest;
   sh->CredentialToken += ({token});
  th = sh->DisplaySettings;
   th->CurrentPage += ({1});
   th->PageSize += ({100});
  th = sh->GetProgramsQuery;
   th->PartnershipStatus->ProgramPartnershipStatusEnum += ({"Active"});

  mapping result = soap->call(args)->GetProgramsResponse->ProgramCollection
   ->Program;

Suggestions are welcome.
--
Stephen.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SOAP in Pike?

Stephen R. van den Berg
Stephen R. van den Berg wrote:
>It helped.  Even though I originally didn't intend to, I got sidetracked and
>implemented something close to a full SOAP-wdsl parser.
>I'm currently determining what the most appropriate sync and/or async interface
>to Pike would be.

>Suggestions are welcome.

Maybe nobody cares, then again, maybe lyskom still has a treasuretrove of
messages on this SOAP-thread...

In any case, lo and behold, there now is usable SOAP in Pike 8.1:
- The wsdl parser works for a lot of types, but probably not all (yet).
  The parser is not a fullblown-faithful implementation according to the RFC,
  it's more like a minimal version that still allows meaningful communication.
  The RFC spec on SOAP is unwieldy, to say the least.
- It uses the fashionable Promise interface.

Sample code:

 Web.SOAP.Promise("https://foo.bar/Logon.svc?wsdl")
  .on_success(lambda(Web.SOAP.Client soap) {
   Web.SOAP.Arguments args, sh;
   args               = soap->getarguments("Logon");
   sh                 = args->LogonRequestMsg;
   sh->Username       = "foo";
   sh->Password       = "bar";
   sh->WebServiceType = "Publisher";

   soap->call(args)
    .on_success(lambda(mixed resp) {
     string token = resp->CredentialToken;
   });
 });

This was about as clean as I could get SOAP (pun intended).
--
Stephen.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SOAP in Pike?

Pontus Östlund
9 nov. 2016 kl. 16:53 skrev Stephen R. van den Berg <[hidden email]>:

Stephen R. van den Berg wrote:
It helped.  Even though I originally didn't intend to, I got sidetracked and
implemented something close to a full SOAP-wdsl parser.
I'm currently determining what the most appropriate sync and/or async interface
to Pike would be.

Suggestions are welcome.

Maybe nobody cares, then again, maybe lyskom still has a treasuretrove of
messages on this SOAP-thread...

In any case, lo and behold, there now is usable SOAP in Pike 8.1:
- The wsdl parser works for a lot of types, but probably not all (yet).
 The parser is not a fullblown-faithful implementation according to the RFC,
 it's more like a minimal version that still allows meaningful communication.
 The RFC spec on SOAP is unwieldy, to say the least.

SOAP is a dirty beast indeed (pun very intended ;)

- It uses the fashionable Promise interface.

Sample code:

Web.SOAP.Promise("https://foo.bar/Logon.svc?wsdl")
 .on_success(lambda(Web.SOAP.Client soap) {
  Web.SOAP.Arguments args, sh;
  args               = soap->getarguments("Logon");
  sh                 = args->LogonRequestMsg;
  sh->Username       = "foo";
  sh->Password       = "bar";
  sh->WebServiceType = "Publisher";

  soap->call(args)
   .on_success(lambda(mixed resp) {
    string token = resp->CredentialToken;
  });
});

Looks nice! :)

The only thing that sticks out to me is that "getarguments()" should be "get_arguments()" to conform to the Pike naming conventions.

This was about as clean as I could get SOAP (pun intended).

A pun is never boring :D

# Pontus

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SOAP in Pike?

Stephen R. van den Berg
Pontus ??stlund wrote:
>> Web.SOAP.Promise("https://foo.bar/Logon.svc?wsdl")
>>  .on_success(lambda(Web.SOAP.Client soap) {
>>   Web.SOAP.Arguments args, sh;
>>   args               = soap->getarguments("Logon");
>>   sh                 = args->LogonRequestMsg;
>>   sh->Username       = "foo";
>>   sh->Password       = "bar";
>>   sh->WebServiceType = "Publisher";

>>   soap->call(args)
>>    .on_success(lambda(mixed resp) {
>>     string token = resp->CredentialToken;
>>   });
>> });

>The only thing that sticks out to me is that "getarguments()" should be "get_arguments()" to conform to the Pike naming conventions.

Ok, fixed.
Also fixed some other things.
Brushed up the documentation a bit.
We still need some test-suite entries for this, but that's not for today.
If anyone wants to step in for those, please do...
The only thing that can be tested is providing the Web.SOAP.Client.create()
with a prefabricated XML-wsdl description, then use get_arguments and
set some parameters.

Incidentally, internally in SOAP.Client I used the JavaScript then() method
to chain the Futures/Promises to preserve my own sanity.

Chaining futures/promises without using the then() method is a bit of
a challenge.
--
Stephen.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SOAP in Pike?

Stephen R. van den Berg
And then I stumble upon this:
https://github.com/pikelang/Pike-Modules/tree/master/Standards.pmod/WSDL.pmod

Pontus, it seems to have been abandoned by you about six years ago.
Was it too buggy to reuse?
I do seem to notice that the code-footprint is pretty large.  Almost as
unwieldy as the RFC itself ;-).

What about the parameter interface.  Anything in that code worth copying over
to my new implementation in Pike 8.1?
--
Stephen.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SOAP in Pike?

Pontus Östlund
10 nov. 2016 kl. 09:57 skrev Stephen R. van den Berg <[hidden email]>:
>
> And then I stumble upon this:
> https://github.com/pikelang/Pike-Modules/tree/master/Standards.pmod/WSDL.pmod
>
> Pontus, it seems to have been abandoned by you about six years ago.
> Was it too buggy to reuse?
> I do seem to notice that the code-footprint is pretty large.  Almost as
> unwieldy as the RFC itself ;-).

Hehe, well I think I came to the conclusion I was in too deep water. I have no idea at this moment what could and what couldn't be considered as reusable.

> What about the parameter interface.  Anything in that code worth copying over
> to my new implementation in Pike 8.1?

Do you mean the Param class from the SOAP-helper repo? I can't find any parameter interface in the old WSDL stuff. But the Param class in SOAP-helper can handle quite complex parameters, so that one could probably be of use.

Personally I hope SOAP dies :D
SOAP is awesome if you are programming in Java or C# where there are tools to auto-generate entire API's for you from the WSDL files. But if you don't have that luxury it's just overly verbose and complex. I prefer REST API's with JSON :)

# Pontus


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SOAP in Pike?

Chris Angelico
On Sat, Nov 12, 2016 at 2:12 AM, Pontus Östlund <[hidden email]> wrote:
> SOAP is awesome if you are programming in Java or C# where there are tools to auto-generate entire API's for you from the WSDL files. But if you don't have that luxury it's just overly verbose and complex. I prefer REST API's with JSON :)
>

No kidding!

The last time I had to deal with an XML-based API, I put together a
little parser that turned it all into a load of
mappings/arrays/strings, just to give myself half a chance of writing
mildly readable code (because, of course, the info I wanted was about
fifty levels deep in the structure, too). Was a gross pile of steaming
excrement, though, and not something that belongs in the stdlib.

ChrisA

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SOAP in Pike?

Lance Dillon-2
Yes, I wrote a couple of modules that used xmlrpc, one to interface with Red Hat Satellite Server 5 (and Spacewalk 5), and another to work with Nessus.  It was kind of a hassle to work with the xmlrpc stuff, and Nessus was a weird combination of xmlrpc and maybe post or something, I had to do some weird stuff to get it working.  Unfortunately I can't find my nessus module.  I'll have to dig around my code.


On Friday, November 11, 2016 10:49 AM, Chris Angelico <[hidden email]> wrote:


On Sat, Nov 12, 2016 at 2:12 AM, Pontus Östlund <[hidden email]> wrote:

> SOAP is awesome if you are programming in Java or C# where there are tools to auto-generate entire API's for you from the WSDL files. But if you don't have that luxury it's just overly verbose and complex. I prefer REST API's with JSON :)

>

No kidding!

The last time I had to deal with an XML-based API, I put together a
little parser that turned it all into a load of
mappings/arrays/strings, just to give myself half a chance of writing
mildly readable code (because, of course, the info I wanted was about
fifty levels deep in the structure, too). Was a gross pile of steaming
excrement, though, and not something that belongs in the stdlib.

ChrisA



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SOAP in Pike?

Stephen R. van den Berg
In reply to this post by Pontus Östlund
Pontus ??stlund wrote:
>> What about the parameter interface.  Anything in that code worth copying over
>> to my new implementation in Pike 8.1?

>Do you mean the Param class from the SOAP-helper repo? I can't find any
> parameter interface in the old WSDL stuff. But the Param class in SOAP-helper
> can handle quite complex parameters, so that one could probably be of use.

Ok.  I'll quickly flip through that to see if there is anything worth
salvaging.  I sort-of solved the parameter assignment by simply creating
a nested mapping structure which I then overload the = operator on; i.e.
the wdsl precreates the nested mapping structure, so there is no need to
parse mappings anymore.
The function results are simply presented as a nested mapping.

>Personally I hope SOAP dies :D
>SOAP is awesome if you are programming in Java or C# where there are tools to auto-generate entire API's for you from the WSDL files. But if you don't have that luxury it's just overly verbose and complex. I prefer REST API's with JSON :)

Yes, well, as you might have guessed, I stumbled upon a customer that insists
on using it, so I either had to make it at least digestible in Pike or
(god forbid) access it from PHP or Java.
It definitely is not for the faint of heart.

Fun fact (perhaps): instead of reading the RFC, I just massaged the wsdl XML
I got from the APIs I'm supposed to use till the point where I could actually
assign values and get something back.  It is surprising how little code one
actually needs to parse wsdl into something sensible (mappings).
It's sort-of a clean-room implementation of SOAP/wsdl, reverse engineered
from on-the-wire XML.
--
Stephen.

Loading...