SOAP WSDL request strugle

251 views
Skip to first unread message

Yebach

unread,
Dec 22, 2017, 3:25:43 AM12/22/17
to web...@googlegroups.com
Hello

I have to create a SOAP client (later also a service will be needed). It is my first time so please bare with me on this one as I do not have a proper understanding of this.

If I understand the whole process it is smth like this. I send a WSDL request where URL contains "?wsdl". This way I can see all the methods provided by the server. This is called GET.
Now after that i can get a definition of an xml "envelope" with which I filter which results I want. I use POST method to call an URL - without "?wdsl"  send this to some method and it should return xml with data provided?

Using app SOAPUI i get everything, but I find it impossible to get trough with any python environment.

I would like to call method getEmployed. This is the envelope

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cet="http://xxxx.dd">
   <soapenv:Header/>
   <soapenv:Body>
      <cet:GetEmployedElement>
         <!--Zero or more repetitions:-->
         <cet:GetEmployed>
            <cet:OrganizationCode></cet:OrganizationCode>
            <cet:LastName></cet:LastName>
            <cet:FirstName></cet:FirstName>
            <cet:AktCard></cet:AktCard>
            <cet:JobAgreementType></cet:JobAgreementType>
            <cet:Mferac></cet:Mferac>
         </cet:GetEmployed>
      </cet:GetEmployedElement>
   </soapenv:Body>
</soapenv:Envelope>

this way I should receive all the employees 
my code

xml = ("""<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cet="http://xxx.yy">
<soapenv:Header/>
<soapenv:Body>
<cet:GetEmployedElement>
<!--Zero or more repetitions:-->
<cet:GetEmployed>
<cet:OrganizationCode></cet:OrganizationCode>
<cet:LastName></cet:LastName>
<cet:FirstName></cet:FirstName>
<cet:AktCard></cet:AktCard>
<cet:JobAgreementType></cet:JobAgreementType>
<cet:Mferac></cet:Mferac>
</cet:GetEmployed>
</cet:GetEmployedElement>
</soapenv:Body>
</soapenv:Envelope>
""")

from gluon.contrib.pysimplesoap.client import SoapClient, SoapFault
client = SoapClient (wsdl="https://www.xxx.yy/some/more/url?wsdl", location="https://www.xxx.yy", cacert=None, trace=True)

print client.send('getEmployed',xml=xml)

response = client.getEmployed()
print response

I get either urllib2.URLError: <urlopen error [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>
or error 405.

Any proper explanation and/or example would be good.

thank you
 

Dave S

unread,
Dec 22, 2017, 3:57:25 PM12/22/17
to web...@googlegroups.com


On Friday, December 22, 2017 at 12:25:43 AM UTC-8, Yebach wrote:
Hello

I have to create a SOAP client (later also a service will be needed). It is my first time so please bare with me on this one as I do not have a proper understanding of this.

If I understand the whole process it is smth like this. I send a WSDL request where URL contains "?wsdl". This way I can see all the methods provided by the server. This is called GET.
Now after that i can get a definition of an xml "envelope" with which I filter which results I want. I use POST method to call an URL - without "?wdsl"  send this to some method and it should return xml with data provided?


I don't deal with the wsdl myself (on the client side).  I use suds

from suds.client import Client
from suds.transport.http import HttpAuthenticated

and when I instantiate a client, the WSDL is handled for me (aside from my choosing a filename to store it in).

def start(self):
   url1
= 'http://' + self.loggerIP + ':' + self.loggerPort \
               
+ '/MyServer/default/call/soap?WSDL'
   
self.client = Client(url=url1, username='logusr', password='mypassword1234567890')
   
self.client.set_options(cache=None)
   authenticationHeader
= {
                 
"SOAPAction" : "ActionName",
                 
"Authorization" : "Basic %s" % base64string
                 
}

(self, because I actually made classes in the code I'm quoting; this is part of t)

Then the hook to do stuff (also part of the class)

def getLogStatus(self, targetIP):
   
return self.client.service.LastStatus(targetID)

The "main" code looks like:

logClient = LoggerClient("10.3.171.71", "8080",
                           
'file:///path/logserver-wsdl.xml')
logClient
.start()
result
= logClient.getLogStatus(target.IP)
failed
= result.rfind(" failed")
   
if failed > 0:
       result
= result[0:failed - 1]
print "target has reported in at %s" % (result)


(result is a string, either just an ISO-format datetime, or the datetime with " failed" appended.)

I use PySimpleSoap on the server ... finding that led to my finding web2py.  I think a client using PySimpleSoap would look similar to my example, but it appears I didn't get around to that yet.

Also, my technique does require that you know what the calls are, but that's either in the server API documentation or you can get the WSDL and eyeball it.

/dps
(minor edit at 10:30)

T.R.Rajkumar

unread,
Dec 23, 2017, 4:36:43 AM12/23/17
to web2py-users
I do like this

        from gluon.contrib.pysimplesoap.client import SoapClient
        client = SoapClient(wsdl="http://172.16.164.64/ws_ts2admin/ts2admin.asmx?WSDL")
        rs = client.ValidateLogin(lcUname, lcPwd, lnCode, lcMsg)
        rs1 = rs['ValidateLoginResult']
        ret_code = rs1['Code']
        ret_msg = rs1['Msg']
        #print ret_msg
        #lcAppId = 'vb_cont'
        if ret_code == 1:
            #rs2 = client.ValidateAppUser(lcUname,lcAppId)           
            #rs3 = rs2['ValidateAppUserResult']
            #rs4 = rs3['Code']
            #if rs4 == 1:
                session.logged_in = 'True'
                session.uname = lcUname
                redirect(URL('lp','lp'))
               
            #else:
                #response.flash ='Not a user of app.'
        else:
            response.flash = ret_msg

Dave S

unread,
Dec 23, 2017, 5:25:42 AM12/23/17
to web2py-users


On Saturday, December 23, 2017 at 1:36:43 AM UTC-8, T.R.Rajkumar wrote:
I do like this


Server side, or client?
/dps
 

T.R.Rajkumar

unread,
Dec 24, 2017, 1:50:40 AM12/24/17
to web2py-users
In the controller login.py

T.R.Rajkumar

unread,
Dec 24, 2017, 1:56:45 AM12/24/17
to web2py-users
ts2admin.asmx is the web service. ValidateLogin is the method of that service. I pass the username and password to that service and it returns the result. If ret_code is 1 I allow login to my application LP.

Dave S

unread,
Dec 25, 2017, 2:22:56 AM12/25/17
to web2py-users


On Saturday, December 23, 2017 at 10:56:45 PM UTC-8, T.R.Rajkumar wrote:
ts2admin.asmx is the web service. ValidateLogin is the method of that service. I pass the username and password to that service and it returns the result. If ret_code is 1 I allow login to my application LP.

Ah, thanks,  That makes sense, you're using a third-party service via SOAP to handle authorization, like a single-signon setup. 

/dps

Reply all
Reply to author
Forward
0 new messages