Shokhrukh Shodiev
Shokhrukh Shodiev

Reputation: 9

Spyne soap service returning json output not xml

This is my service in spyne for integrating client server. It works well when i tested it in Postman, SoapUI and Boomerang(extension for soap request/response). It sends and gets xml format. But client said that he got Json response instead of xml. I did not know how actually this happened. Maybe above tools are formatting in their way. I googled a lot found similar question.According to answer i have to change _returns=AnyDict to _returns=Iterable(Unicode) but it did not work for me

class RussianIntegrationApiView(ServiceBase):

    @rpc(Request91Type,
         _returns=AnyDict,
         _out_variable_name="Response91")
    def Request91(ctx, request91type):
        try:
            logging.info(
                f'Initialized objects for Response91')
            x = elem2dict(ctx.in_document)
            request91_dict = x['Body']['Request91']['Request_91']['Request91']
            cert_num = request91_dict['Certificate']['Number']
            return {
                "GUID": request91_dict['GUID'] or None,
                "SendDateTime": request91_dict['SendDateTime'] or None, 
                "Certificate": {
                    "Date": request91_dict['Certificate']['Date'] or None,
                    "Number": request91_dict['Certificate']['Number'] or None,
                    "Blanc": request91_dict['Certificate']['Blanc'] or None,
                    "CountryCode": request91_dict['Certificate']['CountryCode'] or None,
                    "ExpirationDate": request91_dict['Certificate']['ExpirationDate'] or None,
                    "Canceled": request91_dict['Certificate']['Canceled'] or None,
                    "IssuePlace": request91_dict['Certificate']['IssuePlace'] or None,
                    "Inspector": request91_dict['Certificate']['Inspector'] or None,
                },
                "Status": request91_dict['Status'] or None,
                "StatusCode": request91_dict['StatusCode'] or None,
                "Inspector": request91_dict['Inspector'] or None,
            }

I will appreciate any help, tip or useful link to solve this problem.

This is the appication object part

RussianIntegrationApiView.event_manager.add_listener('method_return_string',
                                                     on_method_return_string)
application = Application([RussianIntegrationApiView],
                          'https://argusgate.fitorf.ru/srv/ws/uz3',
                          name='UZ3SoapBinding',
                          in_protocol=Soap11(validator='soft'),
                          out_protocol=Soap11())

russian_api_service = DjangoApplication(application)


def get_wsdl_file_russian(request):

    with open('apps/invoice/api/russian_webservice/russian.wsdl', 'r') as f:
        docs = f.read()
    return HttpResponse(docs, content_type='text/xml; charset=utf-8')


@csrf_exempt
def russian_service_dispatcher(request):
    if request.get_full_path() in ('/UzGosKarantinWebService/russian/?wsdl',
                                   '/UzGosKarantinWebService/russian?wsdl'):
        return get_wsdl_file_russian(request)
    return russian_api_service(request)

Upvotes: 0

Views: 98

Answers (0)

Related Questions