0

My client.py looks like this:

from SOAPpy import WSDL
wsdlFile = 'D:/Downloads/w1.1.wsdl'
server = WSDL.Proxy(wsdlFile) 
server.soapproxy.config.dumpSOAPOut = 1     
server.soapproxy.config.dumpSOAPIn = 1
result = server.packageRequest({'wrongParameter': 'wrong value'})
print result 

and my server.py:

import SOAPpy
def packageRequest(data):
    return "Hello World"
server = SOAPpy.SOAPServer(("localhost", 8080))
server.registerFunction(packageRequest)
server.serve_forever()

The most important is w1.1.wsdl because it defines restrictions for example for input data:

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2013 sp1 (http://www.altova.com) by Krzysztof (Wroclaw University of Technology) -->
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://new.webservice.namespace" targetNamespace="http://new.webservice.namespace">
    <wsdl:types>
        <xs:schema targetNamespace="http://new.webservice.namespace" elementFormDefault="qualified"/>
        <xsi:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema" targetNamespace="http://new.webservice.namespace" elementFormDefault="qualified">
            <xsi:element name="request">
                <xsi:complexType>
                    <xsi:sequence>
                        <xsi:element name="info">
                            <xsi:complexType>
                                <xsi:attribute name="company" type="xs:integer" use="required"/>
                                <xsi:attribute name="packageId" type="xs:integer" use="required"/>
                                <xsi:attribute name="storehouseId" type="xs:integer" use="required"/>
                                <xsi:attribute name="giving" type="xs:dateTime" use="required"/>
                                <xsi:attribute name="send" type="xs:dateTime" use="required"/>
                                <xsi:attribute name="weight" type="xs:integer" use="required"/>
                                <xsi:attribute name="unit" type="xs:string" use="required"/>
                            </xsi:complexType>
                        </xsi:element>
                        <xsi:element name="recipient">
                            <xsi:complexType>
                                <xsi:sequence>
                                    <xsi:element name="firstname" type="xs:string"/>
                                    <xsi:element name="lastname" type="xs:integer"/>
                                    <xsi:element name="street" type="xs:string"/>
                                    <xsi:element name="city" type="xs:string"/>
                                    <xsi:element name="zip">
                                        <xsi:simpleType>
                                            <xsi:restriction base="xs:string">
                                                <xsi:pattern value="[0-9]{2}-[0-9]{3}"/>
                                            </xsi:restriction>
                                        </xsi:simpleType>
                                    </xsi:element>
                                </xsi:sequence>
                            </xsi:complexType>
                        </xsi:element>
                        <xsi:element name="sender">
                            <xsi:complexType>
                                <xsi:sequence>
                                    <xsi:element name="firstname" type="xs:string"/>
                                    <xsi:element name="lastname" type="xs:string"/>
                                    <xsi:element name="street" type="xs:string"/>
                                    <xsi:element name="city" type="xs:string"/>
                                    <xsi:element name="zip">
                                        <xsi:simpleType>
                                            <xsi:restriction base="xs:string">
                                                <xsi:pattern value="[0-9]{2}-[0-9]{3}"/>
                                            </xsi:restriction>
                                        </xsi:simpleType>
                                    </xsi:element>
                                </xsi:sequence>
                            </xsi:complexType>
                        </xsi:element>
                    </xsi:sequence>
                </xsi:complexType>
            </xsi:element>
        </xsi:schema>
        <xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema" targetNamespace="http://new.webservice.namespace" elementFormDefault="qualified">
            <xs:element name="response">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="companyId"/>
                        <xs:element name="packageId"/>
                        <xs:element name="packageGivingDate"/>
                        <xs:element name="responseSendDate"/>
                        <xs:element name="packageWeight"/>
                        <xs:element name="packageUnit"/>
                        <xs:element name="recipient">
                            <xs:complexType>
                                <xs:sequence>
                                    <xs:element name="firstName"/>
                                    <xs:element name="lastName"/>
                                    <xs:element name="city"/>
                                    <xs:element name="zip"/>
                                    <xs:element name="street"/>
                                </xs:sequence>
                            </xs:complexType>
                        </xs:element>
                        <xs:element name="sender">
                            <xs:complexType>
                                <xs:sequence>
                                    <xs:element name="firstName"/>
                                    <xs:element name="lastName"/>
                                    <xs:element name="city"/>
                                    <xs:element name="zip"/>
                                    <xs:element name="street"/>
                                </xs:sequence>
                            </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:schema>
    </wsdl:types>
    <wsdl:message name="request">
        <wsdl:part name="parameter" element="tns:request"/>
    </wsdl:message>
    <wsdl:message name="response">
        <wsdl:part name="parameter" element="tns:response"/>
    </wsdl:message>
    <wsdl:portType name="NewPortType">
        <wsdl:operation name="packageRequest">
            <wsdl:input message="tns:request"/>
            <wsdl:output message="tns:response"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="NewBinding" type="tns:NewPortType">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="packageRequest">
            <soap:operation soapAction="packageRequest" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="NewService">
        <wsdl:port name="NewPort" binding="tns:NewBinding">
            <soap:address location="http://localhost:8080/"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

If I run my client.py I get response "Hello World!". Why? I expect error that input data are wrong (WDSL defines input data like company, packageId, storehouseId ... but I give only useless dictionary {'wrongParameter': 'wrong value'})

What I did wrong? Why WSDL validation doesn't work ?

David Silva
  • 1,939
  • 7
  • 28
  • 60

1 Answers1

0

Why WSDL validation doesn't work ?

Because your web service takes in some data and outputs a "Hello World!" string. That's all it does.

Just to see what I mean, change your server code to this and look at the SOAP messages and the result you get:

import SOAPpy

def packageRequest(data):
    result = {"HelloWorld": "Message from server"}
    if isinstance(data, str):
        result["plainString"] = data
    else:
        result.update([(k, v) for k, v in data.__dict__.iteritems() if not k.startswith("_")])
    return result

server = SOAPpy.SOAPServer(("localhost", 8080))
server.registerFunction(packageRequest)
server.serve_forever()

You have to properly implement the packageRequest method and handle validation yourself. The WSDL has nothing to do with it.

A web service is a set of operations exposed on the network. It accepts properly formatted SOAP messages and outputs SOAP messages. But if a client needs to call your web service how does it know how to format the message? Enter WSDL!

You use a WSDL to describe the contract that a client must follow to successfully interact with your web service. It's used as a form of documentation and a way of automatically generating client stub that knows how to call your web service.

You can also use the WSDL to generate a server skeleton but I'm not aware if SOAPpy can do that (I think it can only create a client side proxy) so you need to do the implementation yourself and reject badly formatted messages.

Bogdan
  • 23,890
  • 3
  • 69
  • 61