This question never got an answer. I never got the WSGISOAPHandler(dispatcher)
to work either since it would always throw assert type(data) is bytes, "write() argument must be a bytes instance"
in /usr/lib/python3.8/wsgiref/handlers.py
on line 297.
Since wsgiref.simple_server import make_server
is from python2 which treats encoding differently i just decided instead to use from http.server import HTTPServer
to avoid all these encoding issues.
Here is an example i made using a Client and Server:
Server:
from pysimplesoap.server import SoapDispatcher, SOAPHandler
from http.server import HTTPServer
def cityweatherreport(city_name):
#Some Code here to fetch weather info:
weather_report = f"""Weather in {city_name} is """
print('weather_report: ', weather_report)
return{'weather_report': weather_report}
def server_accepting_soap_requests():
dispatcher = SoapDispatcher(
name="WeatherServer",
location="http://127.0.0.1:8050/",
action='http://127.0.0.1:8050/', # SOAPAction
namespace="http://example.com/pysimplesoapsamle/",
prefix="ns0",
trace = True,
ns = True)
dispatcher.register_function('CityWeatherReport', cityweatherreport,
returns={'weather_report': str},
args={'city_name': str})
print('starting server')
httpd = HTTPServer(("", 8050), SOAPHandler)
httpd.dispatcher = dispatcher
httpd.serve_forever()
def main():
server_accepting_soap_requests()
if __name__ == '__main__':
main()
Client:
from pysimplesoap.client import SoapClient
def test_weather_conversion_service():
client = SoapClient(
location="http://localhost:8050/",
action='http://localhost:8050/', # SOAPAction
namespace="http://example.com/sample.wsdl",
soap_ns='soap',
trace=True,
ns="ns0",
)
response = client.CityWeatherReport(city_name="Berlin")
result = response.weather_report
print('result: ', result)
def main():
test_weather_conversion_service()
if __name__ == '__main__':
main()
For running it remote on a dedicated machine i would suggest a tool like screen: screen -d -m -S <username> python3 <pythonfile.py>