This entry will show you how to model a dotnet valid wsdl file, how to send dotnet valid responses from php and finally how to connect a c# client. This is the wsdl ‚DOTNET‘ way 3->5->7->2 to continue Johann’s previous post. It is easy, at least if you know what desires the Microsoft’s xml-serializer. To put the difficulty level one step higher we define and respond with a nested array.
A general knowledge of wsdl should exist. You know ‚binding‘, ‚porttype‘ and ‚message‘ … lets move to the harder part: defining the complex type for a nested array that can be read by dotNet.
<xsd:complexType name="Users">
<xsd:complexContent>
<xsd:restriction base="soapenc:Array">
<xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="typens:User[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
This arrayType with the name ‚Users‘ links to a single ‚User‘
<xsd:complexType name="User">
<xsd:all>
<xsd:element name="Firstname" type="xsd:string" />
<xsd:element name="Lastname" type="xsd:string" />
<xsd:element name="Street" type="xsd:string" />
<xsd:element name="ZIP" type="xsd:int" />
<xsd:element name="City" type="xsd:string" />
<xsd:element name="Country" type="xsd:string" />
</xsd:all>
</xsd:complexType>
Remember to name the webreference something like ‚blog.thinkphp.de‘ to add the namespaces to the classes.
Access the user properties
At any following line now add a breakpoint to trace the local variables.
The PHP and PEAR_SOAP version is somewhat uncomfortable. But I will show you the tricky part of a dotNet-valid soap response.
<Users xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="soap-enc:Array" soap-enc:arrayType="auth:User[2]">
Have a look at the last attribute holding the ’soap-enc‘ namespace. Figuring out that dotNet xml-serializer needs the exact size of the response array took us several hours. Also make sure that variable names defined in the wsdl file have the same name and type in the response. That is also a common mistake.
<Users xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="soap-enc:Array" soap-enc:arrayType="auth:User[2]">
<User xsi:type="auth:User">
<Firstname xsi:type="xsd:string">Manfred</Firstname>
<Lastname xsi:type="xsd:string">Weber</Lastname>
<Street xsi:type="xsd:string">Street1</Street>
<ZIP xsi:type="xsd:int">81543</ZIP>
<City xsi:type="xsd:string">Munich</City>
<Country xsi:type="xsd:string">Germany</Country>
</User>
<User xsi:type="auth:User">
<Firstname xsi:type="xsd:string">Wolfram</Firstname>
<Lastname xsi:type="xsd:string">Kriesing</Lastname>
<Street xsi:type="xsd:string">Street2</Street>
<ZIP xsi:type="xsd:int">81544</ZIP>
<City xsi:type="xsd:string">Munich</City>
<Country xsi:type="xsd:string">Germany</Country>
</User>
</Users>
Most important when writing the server with php4 and the pear package is to rewrite the response message because PEAR_SOAP does not define the size of arrays.
As announced PHP5 offers greater flexibility. No need for rewriting responses.
During the development process we discovered following tools as helpful.
– Webstudio 2.0
– Fiddler HTTP Proxy and Debugger
Author:
Manfred / Mayflower
Schreibe einen Kommentar