When I call a SOAP request from suds python ,it is giving Object reference not set to an instance of an object.I created the request objects from wsdl and pass the object to the method .It is throwing Object reference not set to an instance of an object..Alternatively I sent the request as Raw XML ,it is also not working .Find the code below .The SOAP request implemented WS Addressing .I updated soap header ((WS Addressing) )and sent it .Before updating soap header(WS Addressing) ,I got Bad Request
def main(): from suds.sax.element import Element from suds.sax.attribute import Attribute from suds.sax.text import Raw from suds.client import Client from suds.bindings import binding binding.envns=('SOAP-ENV', 'http://www.w3.org/2003/05/soap-envelope') from suds.plugin import MessagePlugin class MyPlugin(MessagePlugin): def marshalled(self, context): foo = context.envelope.getChild('Header') foo.attributes.append(Attribute('xmlns:wsa','http://www.w3.org/2005/08/addressing')) https = suds.transport.https.HttpTransport() urlvalue=https://wvua-eucluw-iws-446.aceins.com:446/Xxxxyyy/DocumentService/DocumentService.svc?wsdl client = Client(urlvalue ,unwrap=False,transport=https,plugins=[MyPlugin()]) wsans = ('wsa', 'http://schemas.xmlsoap.org/ws/2004/08/addressing') mustAttribute = Attribute('SOAP-ENV:mustUnderstand', 'true') msgId5 = Element('Action', ns=wsans).setText('http://xxxx.com/Xxxxyyy/DocumentService/2016/06/DocumentService/GetSpecificDocument') msgId3 = Element('To', ns=wsans).setText('https://wvua-eucluw-iws-446.aceins.com:446/Xxxxyyy/DocumentService/DocumentService.svc') msgId3.append(mustAttribute) client.options.cache.clear() client.options.headers.clear() client.set_options(soapheaders=[ msgId5,msgId3]) client.set_options(headers={"Content-type" : 'application/soap+xml; charset=UTF-8','SoapAction':'http://xxxx.com/Xxxxyyy/DocumentService/2016/06/DocumentService/GetSpecificDocument'}) client.options.prettyxml = True # Constructing request objects spcificdocumentrequest =client.factory.create('ns0:SpecificDocumentRequest') spcificdocumentrequest.DocumentGUID ="D589A450-D3CA-4D55-8A0D-1D47E0DD01A2" #print (spcificdocumentrequest) envrionmentdata=client.factory.create('ns0:EnvironmentData') envrionmentdata.MessageGUID = "msg-ID" envrionmentdata.CountryCode = "GB" envrionmentdata.SourceSystem = "TrackandTrace" envrionmentdata.XxxxyyyLogonID = "TrackandTrace" envrionmentdata.XxxxyyyEnvironment = "UAT" spcificdocumentrequest.EnvironmentData=envrionmentdata logging.basicConfig(level=logging.DEBUG) logging.getLogger('suds.client').setLevel(logging.DEBUG) xml=Raw("""<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV=http://www.w3.org/2003/05/soap-envelope xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:wsa=http://schemas.xmlsoap.org/ws/2004/08/addressing xmlns:ns0=http://xxxx.com/Xxxxyyy/DocumentService/2016/06 xmlns:ns1=http://www.w3.org/2003/05/soap-envelope xmlns:ns2=http://xxxx.com/Xxxxyyy/DocumentService/2016/06> <SOAP-ENV:Header> <wsa:Address>http://www.w3.org/2005/08/addressing</wsa:Address> <wsa:Action>http://xxxx.com/Xxxxyyy/DocumentService/2016/06/DocumentService/GetSpecificDocument</wsa:Action> <wsa:To SOAP-ENV:mustUnderstand="true">https://wvua-eucluw-iws-446.aceins.com:446/Xxxxyyy/DocumentService/DocumentService.svc</wsa:To> </SOAP-ENV:Header> <ns1:Body> <ns0:GetSpecificDocument> <ns0:request> <ns2:DocumentGUID>D589A450-D3CA-4D55-8A0D-1D47E0DD01A2</ns2:DocumentGUID> <ns2:EnvironmentData> <ns2:MessageGUID>msg-ID</ns2:MessageGUID> <ns2:CountryCode>GB</ns2:CountryCode> <ns2:SourceSystem>TrackandTrace</ns2:SourceSystem> <ns2:XxxxyyyLogonID>TrackandTrace</ns2:XxxxyyyLogonID> <ns2:XxxxyyyEnvironment>UAT</ns2:XxxxyyyEnvironment> </ns2:EnvironmentData> </ns0:request> </ns0:GetSpecificDocument> </ns1:Body> </SOAP-ENV:Envelope> """) # print (spcificdocumentrequest) response =client.service.GetSpecificDocument(spcificdocumentrequest) #response =client.service.GetSpecificDocument(xml)I got below error
Error:Message=((Fault){
Code =
(Code){
Value = "s:Receiver"
Subcode =
(Subcode){
Value = "a:InternalServiceFault"
}
}
Reason =
(Reason){
Text = "Object reference not set to an instance of an object."
}
StackTrace = " at xxxx.xxxxyyyy.DocumentService.ServiceImplementation.DocumentService.GetSpecificDocument(GetSpecificDocumentRequest request)
Larz60+ write Sep-28-2022, 09:16 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time, please use BBCode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time, please use BBCode tags on future posts.