I need to write a soap service which gets soap request and return soap response. I could handle sending soap request with zeep client library, everythin correct. But i couldnt send any soap response it shows the same error:)
import logging
from datetime import datetime
from spyne import Application, rpc, ServiceBase, AnyDict
from spyne.protocol.soap import Soap11
from spyne.server.django import DjangoApplication
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from invoice.api.russian_webservice.complex_models import Consignor, Request1Type, Request31Type, Request91Type, CertificateMaximumType, CertificateMinimumType, Response91Type
from exim.models import ExportFSS, ImportFSS
class RussianIntegrationApiView(ServiceBase):
@rpc(Request91Type,
_returns=AnyDict,
_out_variable_name="Response91")
def getResponse91(ctx, request91type):
try:
logging.info(
f'Initialized objects {str(Request91Type).encode("utf-8")}')
error_message = None
error_code = None
import_fss = ImportFSS.objects.create(
number=request91type.certificate.number,
given_date=datetime.strptime(
request91type.certificate.date, '%d.%m.%Y'),
exporter_name=request91type.certificate.consignor.name,
exporter_country=request91type.certificate.departure_country,
exporter_address=request91type.certificate.consignor.place,
importer_name=request91type.certificate.consignee.name,
importer_country=request91type.certificate.destination_country,
importer_address=request91type.certificate.consignee.place,
transport_method=request91type.certificate.transport.declared_type,
transport_number=request91type.certificate.transport.number,
disinfected_date=datetime.strptime(
request91type.certificate.disinfection.date, '%d.%m.%Y'),
treatment_method=request91type.certificate.disinfection.method,
chemical=request91type.certificate.disinfection.chemical,
duration_and_temperature=request91type.certificate.disinfection.temperature_times,
concentration=request91type.certificate.disinfection.concentration,
extra_info=request91type.certificate.additional_info,
)
return {
"GUID": CertificateMinimumType.guid_generate(),
"SendDateTime": "2022-04-11T19:50:11 ",
"Certificate": CertificateMinimumType.generate(),
"Status": "Выдан",
"StatusCode": "1601",
"Inspector": ""
}
except Exception as e:
logging.info(f'Exception occurred: {str(e)}')
def on_method_return_string(ctx):
ctx.out_string[0] = ctx.out_string[0].replace(b'soap11env', b'soapenv')
ctx.out_string[0] = ctx.out_string[0].replace(b'tns', b'mun')
ctx.out_string[0] = ctx.out_string[0].replace(b'GUID', b'm:GUID')
ctx.out_string[0] = ctx.out_string[0].replace(
b'SendDateTime', b'm:SendDateTime')
ctx.out_string[0] = ctx.out_string[0].replace(b'Act', b'm:Act')
ctx.out_string[0] = ctx.out_string[0].replace(b'Date', b'm:Date')
ctx.out_string[0] = ctx.out_string[0].replace(b'Number', b'm:Number')
ctx.out_string[0] = ctx.out_string[0].replace(b'Blanc', b'm:Blanc')
ctx.out_string[0] = ctx.out_string[0].replace(b'OldDate', b'm:OldDate')
ctx.out_string[0] = ctx.out_string[0].replace(
b'CountryCode', b'm:CountryCode')
ctx.out_string[0] = ctx.out_string[0].replace(
b'ExpirationDate', b'm:ExpirationDate')
ctx.out_string[0] = ctx.out_string[0].replace(b'Canceled', b'm:Canceled')
ctx.out_string[0] = ctx.out_string[0].replace(
b'IssuePlace', b'm:IssuePlace')
ctx.out_string[0] = ctx.out_string[0].replace(b'Inspector', b'm:Inspector')
ctx.out_string[0] = ctx.out_string[0].replace(
b'InspectionResult', b'm:InspectionResult')
ctx.out_string[0] = ctx.out_string[0].replace(
b'InspectionResultCode', b'm:InspectionResultCode')
ctx.out_string[0] = ctx.out_string[0].replace(
b'InspectionResultReport', b'm:InspectionResultReport')
ctx.out_string[0] = ctx.out_string[0].replace(
b'InspectionType', b'm:InspectionType')
ctx.out_string[0] = ctx.out_string[0].replace(
b'InspectionTypeCode', b'm:InspectionTypeCode')
ctx.out_string[0] = ctx.out_string[0].replace(
b'Certificates', b'm:Certificates')
ctx.out_string[0] = ctx.out_string[0].replace(b'Status', b'm:Status')
ctx.out_string[0] = ctx.out_string[0].replace(
b'StatusCode', b'm:StatusCode')
ctx.out_string[0] = ctx.out_string[0].replace(b'PDF', b'm:PDF')
print("aaaa-------")
print(ctx.out_string[0].decode('utf-8'))
RussianIntegrationApiView.event_manager.add_listener('method_return_string',
on_method_return_string)
application = Application([RussianIntegrationApiView],
'https://argusgate.fitorf.ru/srv/ws/uz3',
name='UzGosKarantinWSPortBinding',
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)
this is link for wsdl file : https://pastebin.com/459DAje1 this is for complex models: https://pastebin.com/KjV1tWWc
According to the source code you posted, your request name is getResponse91
but according to the error PNG that you posted, you are sending a request for Request91
You need to fix either your request or change the function from getResponse91 to Request91