2

I'm trying to send SOAP request with Python Zeep.

Here is my code:

from zeep import Client

url = 'localhost:8081/ws/?wsdl'
    
def smev_grr():
client = Client(url)
itSystem = '00000000'
nodeId = 'my_node'
factory = client.type_factory('ns1')
specificQuery = client.get_type('ns1:QueryTypeCriteria')
with client.settings():
    response = client.service.Get(itSystem, nodeId, specificQuery('messageTypeCriteria'))
    print(response.text)

I am not sure how to provide QueryTypeCriteria and include messageTypeCriteria with desired request type. With the above code I'm getting the following error:

zeep.exceptions.Fault: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 286; cvc-complex-type.2.4.b: The content of element 'specificQuery' is not complete. One of '{"urn://x-artefacts-smev-gov-ru/services/service-adapter/types":messageTypeCriteria}' is expected.

Using print(client.wsdl.dump()) shows the following:

Prefixes:
     xsd: http://www.w3.org/2001/XMLSchema
     ns0: urn://x-artefacts-smev-gov-ru/services/service-adapter/types/faults
     ns1: urn://x-artefacts-smev-gov-ru/services/service-adapter/types

Global elements:
     
     ns0:SystemFault(ns0:SystemFault)
     ns0:ValidationFault(ns0:ValidationFault)
     ns1:AttachmentHeaderList(AttachmentHeader: ns1:AttachmentHeaderType[])
     ns1:BusinessProcessMetadata(ns1:BusinessProcessMetadata)
     ns1:ClientMessage(ns1:ClientMessage)
     ns1:ErrorMessage(ns1:ErrorMessage)
     ns1:FindMessageQuery(ns1:FindMessageQuery)
     ns1:Message(ns1:Message)
     ns1:MessagePrimaryContent(_value_1: ANY)
     ns1:MessageQuery(ns1:MessageQuery)
     ns1:MessageResult(itSystem: xsd:string, MessageId: xsd:string)
     ns1:PersonalSignature(ns1:XMLDSigSignatureType)
     ns1:QueryResult(ns1:AdapterMessage)
     ns1:QueryResultList(QueryResult: ns1:AdapterMessage[])
     ns1:RequestContent(ns1:RequestContentType)
     ns1:RequestMessage(ns1:RequestMessageType)
     ns1:RequestMetadata(ns1:RequestMetadataType)
     ns1:ResponseContent(ns1:ResponseContentType)
     ns1:ResponseMessage(ns1:ResponseMessageType)
     ns1:ResponseMetadata(ns1:ResponseMetadataType)
     ns1:StatusMessage(ns1:StatusMessage)
     ns1:SyncRequest(ns1:SyncRequest)
     ns1:SyncResponse(ns1:SyncResponse)
     ns1:itSystem(xsd:string)
     ns1:smevMetadata(ns1:SmevMetadata)

Global types:
     xsd:anyType
     xsd:ENTITIES
     xsd:ENTITY
     xsd:ID
     xsd:IDREF
     xsd:IDREFS
     xsd:NCName
     xsd:NMTOKEN
     xsd:NMTOKENS
     xsd:NOTATION
     xsd:Name
     xsd:QName
     xsd:anySimpleType
     xsd:anyURI
     xsd:base64Binary
     xsd:boolean
     xsd:byte
     xsd:date
     xsd:dateTime
     xsd:decimal
     xsd:double
     xsd:duration
     xsd:float
     xsd:gDay
     xsd:gMonth
     xsd:gMonthDay
     xsd:gYear
     xsd:gYearMonth
     xsd:hexBinary
     xsd:int
     xsd:integer
     xsd:language
     xsd:long
     xsd:negativeInteger
     xsd:nonNegativeInteger
     xsd:nonPositiveInteger
     xsd:normalizedString
     xsd:positiveInteger
     xsd:short
     xsd:string
     xsd:time
     xsd:token
     xsd:unsignedByte
     xsd:unsignedInt
     xsd:unsignedLong
     xsd:unsignedShort
     ns0:Fault(code: xsd:string, description: xsd:string)
     ns0:SystemFault(code: xsd:string, description: xsd:string)
     ns0:ValidationFault(code: xsd:string, description: xsd:string)
     ns1:AdapterMessage(smevMetadata: ns1:SmevMetadata, Message: ns1:Message)
     ns1:AttachmentHeaderType(Id: xsd:string, filePath: xsd:string, passportId: xsd:string, SignaturePKCS7: xsd:base64Binary, TransferMethod: ns1:TransferMethodType)
     ns1:BusinessProcessMetadata(_value_1: ANY[])
     ns1:ClientIdCriteria
     ns1:ClientMessage(itSystem: xsd:string, RequestMessage: ns1:RequestMessageType, ResponseMessage: ns1:ResponseMessageType)
     ns1:Content(MessagePrimaryContent: ns1:MessagePrimaryContent, PersonalSignature: ns1:XMLDSigSignatureType, AttachmentHeaderList: ns1:AttachmentHeaderList)
     ns1:CreateGroupIdentity(FRGUServiceCode: xsd:string, FRGUServiceDescription: xsd:string, FRGUServiceRecipientDescription: xsd:string)
     ns1:DynamicRoutingType(DynamicValue: xsd:string[])
     ns1:ErrorMessage(messageType: xsd:string, statusMetadata: ns1:StatusMetadataType, status: ns1:StatusMessageCategory, details: xsd:string, timestamp: xsd:dateTime, type: ns1:ErrorType, fault: ns0:Fault)
     ns1:ErrorType
     ns1:FindMessageQuery(itSystem: xsd:string, specificQuery: ns1:FindTypeCriteria)
     ns1:FindTypeCriteria(messagePeriodCriteria: ns1:MessageIntervalCriteria, messageClientIdCriteria: ns1:MessageClientIdCriteria)
     ns1:IdentifierRoutingType(IdentifierValue: xsd:string[])
     ns1:LinkedGroupIdentity(refClientId: xsd:string, refGroupId: xsd:string)
     ns1:Message(messageType: xsd:string)
     ns1:MessageClientIdCriteria(clientId: xsd:string, clientIdCriteria: ns1:ClientIdCriteria)
     ns1:MessageIntervalCriteria(from: xsd:dateTime, to: xsd:dateTime)
     ns1:MessageQuery(itSystem: xsd:string, nodeId: xsd:string, specificQuery: ns1:QueryTypeCriteria)
     ns1:Metadata(clientId: xsd:string)
     ns1:QueryTypeCriteria(messageTypeCriteria: ns1:TypeCriteria)
     ns1:RegistryRecordRoutingType(RecordId: xsd:int, UseGeneralRouting: xsd:boolean, DynamicRouting: ns1:DynamicRoutingType, IdentifierRouting: ns1:IdentifierRoutingType)
     ns1:RegistryRoutingType(RegistryRecordRouting: ns1:RegistryRecordRoutingType[])
     ns1:Reject(code: ns1:RejectCode, description: xsd:string)
     ns1:RejectCode
     ns1:RequestContentType(content: ns1:Content)
     ns1:RequestMessageType(messageType: xsd:string, RequestMetadata: ns1:RequestMetadataType, RequestContent: ns1:RequestContentType)
     ns1:RequestMetadataType(clientId: xsd:string, linkedGroupIdentity: ns1:LinkedGroupIdentity, createGroupIdentity: ns1:CreateGroupIdentity, nodeId: xsd:string, eol: xsd:dateTime, testMessage: xsd:boolean, TransactionCode: xsd:string, BusinessProcessMetadata: ns1:BusinessProcessMetadata, RoutingInformation: ns1:RoutingInformationType)
     ns1:ResponseContentType(content: ns1:Content, rejects: ns1:Reject[], status: ns1:Status)
     ns1:ResponseMessageType(messageType: xsd:string, ResponseMetadata: ns1:ResponseMetadataType, ResponseContent: ns1:ResponseContentType)
     ns1:ResponseMetadataType(clientId: xsd:string, replyToClientId: xsd:string)
     ns1:RoutingInformationType(DynamicRouting: ns1:DynamicRoutingType, IdentifierRouting: ns1:IdentifierRoutingType, RegistryRouting: ns1:RegistryRoutingType)
     ns1:SmevMetadata(MessageId: xsd:string, ReferenceMessageID: xsd:string, TransactionCode: xsd:string, OriginalMessageID: xsd:string, Sender: xsd:string, Recipient: xsd:string)
     ns1:Status(code: xsd:string, description: xsd:string, parameter: {key: xsd:string, value: xsd:string}[])
     ns1:StatusMessage(messageType: xsd:string, statusMetadata: ns1:StatusMetadataType, status: ns1:StatusMessageCategory, details: xsd:string, timestamp: xsd:dateTime)
     ns1:StatusMessageCategory
     ns1:StatusMetadataType(clientId: xsd:string, originalClientId: xsd:string)
     ns1:SyncRequest(itSystem: xsd:string, RequestMessage: ns1:RequestMessageType)
     ns1:SyncResponse(smevMetadata: ns1:SmevMetadata, Message: ns1:Message)
     ns1:TransferMethodType
     ns1:TypeCriteria
     ns1:XMLDSigSignatureType(_value_1: ANY)

Bindings:
     Soap11Binding: {urn://x-artefacts-smev-gov-ru/services/service-adapter}SMEVServiceAdapterEndpointBinding

Service: SMEVServiceAdapterService
     Port: SMEVServiceAdapterEndpoint (Soap11Binding: {urn://x-artefacts-smev-gov-ru/services/service-adapter}SMEVServiceAdapterEndpointBinding)
         Operations:
            Find(itSystem: xsd:string, specificQuery: ns1:FindTypeCriteria) -> QueryResult: ns1:AdapterMessage[]
            Get(itSystem: xsd:string, nodeId: xsd:string, specificQuery: ns1:QueryTypeCriteria) -> smevMetadata: ns1:SmevMetadata, Message: ns1:Message
            Send(itSystem: xsd:string, RequestMessage: ns1:RequestMessageType, ResponseMessage: ns1:ResponseMessageType) -> itSystem: xsd:string, MessageId: xsd:string

It is evident that I don't know how to build an object with factory and get_type methods. Please help me out. Thanks.

lomach
  • 53
  • 7

1 Answers1

0

The method signature for calling that operation looks like this:

Get(itSystem: xsd:string, nodeId: xsd:string, routerExtraQueue: xsd:string, specificQuery: ns1:QueryTypeCriteria) -> smevMetadata: ns1:SmevMetadata, Message: ns1:Message

It has an extra parameter that I don't see in your call. The call should be:

response = client.service.Get(itSystem, nodeId, routerExtraQueue, specificQuery('messageTypeCriteria'))

and you need to provide a value for the routerExtraQueue also.

That should work.

If it doesn't, then you can troubleshoot things by:

  • using the zeep history plugin to see the SOAP messages your client is trying to send;
  • feeding your WSDL to SoapUI to make successful calls to the service and see how the SOAP messages look like;
  • tweek your code until you get messages from zeep that are equivalent to the ones from SoapUI.
Bogdan
  • 23,890
  • 3
  • 69
  • 61
  • Thanks for your answer. And sorry for providing wrong wdsl dump. There is no routerExtraQueue in my current soapui version. I am not able to provide messageTypeCriteria. It takes no list, no dictionary and no string. So i am completly lost. – lomach Jul 28 '22 at 06:01
  • Your WSDL and your SOAP web service need to be in sync. If they are not, even if you build a message that validates against the WSDL, the service might reject the request. I see you host the service, or at least the WSDL, locally. Can you share the actual WSDL instead of the dump from zeep? – Bogdan Jul 28 '22 at 16:41