kartagis / pysimplesoap

Automatically exported from code.google.com/p/pysimplesoap
0 stars 0 forks source link

Header not being set properly #47

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I have to place the session id in the header on each client call.  Using this 
same WSDL (https://api.clarizen.com/v1.0/Clarizen.svc) in PHP SoapClient, I 
would do the following:

$header[] = new SoapHeader("http://clarizen.com/api", 'Session', array ("ID" => 
$sessionId));
$client->__setSoapHeaders($header);

This generates:  
<SOAP-ENV:Header><ns1:Session><ns1:ID>some 
guid</ns1:ID></ns1:Session></SOAP-ENV:Header>

ns1="http://clarizen.com/api", btw.

In pysimplesoap, I can successfully login and get the session id. Reading some 
examples, it seems that the header can be added as a normal dict entry. But I'm 
not having luck. 

session = response['LoginResult']['SessionId']

#at this point, I can print session and it's good

client['Session'] = { 'ID' : session }

When I try to execute a remote call, I get this as the request XML...

<?xml version="1.0" encoding="UTF-8"?><soap:Envelope 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header/>
<soap:Body>

The server obviously responds that the session is missing:

<s:Envelope 
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode>
s:Client</faultcode><faultstring xml:lang="en-US">Authentication header 
(Session) is missing. Did you forget to 
login?</faultstring></s:Fault></s:Body></s:Envelope>

If a login is needed for Clarizen, they are easy to obtain.  I could create a 
dummy one for my company if needed temporarily.

Thanks.

John

Original issue reported on code.google.com by jpcampb...@gmail.com on 27 Jan 2012 at 10:19

GoogleCodeExporter commented 8 years ago
This is a bug apparently because the WSDL cannot be correctly recognized.

In the meantime, you can try the raw method (building the xml directly):

client = SoapClient(location="https://api.clarizen.com/v1.0/Clarizen.svc", 
namespace='http://clarizen.com/api', trace=True)

headers = SimpleXMLElement("<Headers/>", namespace="http://clarizen.com/api", 
prefix="ns1")
session = headers.add_child("Session")
session['xmlns'] = "http://clarizen.com/api"
session.marshall('ID', 'test123456')

client.location = "https://api.clarizen.com/v1.0/Clarizen.svc"
client.action = "http://clarizen.com/api/IClarizen/Logout"
client.call("Logout", headers=headers)

Original comment by reingart@gmail.com on 28 Jan 2012 at 12:23

GoogleCodeExporter commented 8 years ago
The raw xml method too doesnt seem to work. The header element is not attached 
to the request. This is what I'm trying - 

client = SoapClient(wsdl="file:///C:/myservice.wsdl",trace=True)
client.namespace = "http://api.mynamespace.com/"
query_str = 'Select Id,Name from Product'
headers = SimpleXMLElement("<Header/>")
my_test_header = headers.add_child("SessionHeader")
my_test_header.marshall('Session', 'abcdefg123==')
query_result = client.query(query_str, headers=headers )    

Request XML does not have the Header element. Am I missing something here?

Original comment by ravi.siv...@tarams.com on 14 Feb 2012 at 9:28

GoogleCodeExporter commented 8 years ago
Ravi:

You have to use the raw call method:

query_result_xml = client.call("query", query_str=query_str, headers=headers)

Original comment by reingart@gmail.com on 14 Feb 2012 at 2:02

GoogleCodeExporter commented 8 years ago
Hi did you guys get this issue fixed? 
I'm running into the same issue too (with the raw call method) =...(

Original comment by shih...@gmail.com on 21 Apr 2012 at 1:35

GoogleCodeExporter commented 8 years ago
shihwei: could you attach a test case (.py source code)?

did you try :

query_result_xml = client.call("query", query_str=query_str, headers=headers)

Original comment by reingart@gmail.com on 21 Apr 2012 at 3:34

GoogleCodeExporter commented 8 years ago
I also get the same problem. No matter what method I use to add custom headers 
it won't happen or pysimplesoap will add them in the soap body.

Original comment by mario.r....@gmail.com on 18 May 2012 at 1:00

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
This issue was closed by revision 5079af939058.

Original comment by reingart@gmail.com on 11 Jun 2012 at 11:20

GoogleCodeExporter commented 8 years ago
fixed in client version 1.06b:

http://code.google.com/p/pysimplesoap/source/detail?r=5079af939058933fdadfe8ca0d
a2078d2d4fe3d6

See wsdl and raw tests at:

http://code.google.com/p/pysimplesoap/source/diff?spec=svn5079af939058933fdadfe8
ca0da2078d2d4fe3d6&r=5079af939058933fdadfe8ca0da2078d2d4fe3d6&format=side&path=/
tests/issues_tests.py

Original comment by reingart@gmail.com on 11 Jun 2012 at 11:26