PHP 5.29 - SOAP Extension: Contract First Services

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
soapsuds
Forum Newbie
Posts: 5
Joined: Fri Aug 28, 2009 12:53 pm

PHP 5.29 - SOAP Extension: Contract First Services

Post by soapsuds »

Hello,

I will post the final code when done as it will have alot of constructive examples of have to handle problems not encountered so often.

I have a set of XML schemas from Amazon Seller Central needed to generate XML feeds from them.

Using XML Spy I have created a WSDL. I had to change 2 missing type definitions in Amazon's schemas (in CE.xsd). I also had name the complexType that is the root element (amzn-envelope.xsd) of the Amazon XML schemas being imported into the WSDL. I had to pull a simpleType out of the root complexType and name that (amzn-envelope.xsd). These things were done so that the set of Amazon schemas would validate with XML Spy.

Now using the SOAP extension I have created a (so far) simple SOAP client / server with the created WSDL being using to configure them. The SOAP extension doesn't seem to do anything though with the imported schemas in the WSDL.

Question: How do I access the information imported via the WSDL import in PHP?

Question: If I can't access these schemas as imported now, what is the way to properly import them into a SOAP server?

Question: Any other advice or hints?


Inlined is the WSDL and the PHP SOAP client/server. Attached are some of the imported schemas from Amazon.

AmazonServices.wsdl

Code: Select all

 
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://127.0.0.1/Amazon/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns="http://schemas.xmlsoap.org/soap/encoding/" name="AmazonServices" targetNamespace="http://127.0.0.1/Amazon/">
    <xsd:import namespace="http://127.0.0.1/Amazon/" location="schemas/Amazon/amzn-envelope.xsd"/>
    <wsdl:types>
        <xsd:schema targetNamespace="http://127.0.0.1/Amazon/">
            <xsd:element name="AmazonServices">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="AmazonXMLFeed" type="AmazonXMLEnvelope"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="AmazonServicesResponse">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="AmazonXMLFeed" type="AmazonXMLEnvelope"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="AmazonServicesRequest">
        <wsdl:part name="AmazonXMLFeedParameters" element="tns:AmazonServices"/>
    </wsdl:message>
    <wsdl:message name="AmazonServicesResponse">
        <wsdl:part name="AmazonXMLFeedParameters" element="tns:AmazonServicesResponse"/>
    </wsdl:message>
    <wsdl:portType name="AmazonServicesPort">
        <wsdl:operation name="AmazonServices">
            <wsdl:input message="tns:AmazonServicesRequest"/>
            <wsdl:output message="tns:AmazonServicesResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="AmazonServicesSOAP" type="tns:AmazonServicesPort">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="AmazonServices">
            <soap:operation soapAction="http://127.0.0.1/Amazon/AmazonServices"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="AmazonServices">
        <wsdl:port name="AmazonServicesSOAP" binding="tns:AmazonServicesSOAP">
            <soap:address location="http://127.0.0.1/Amazon/AmazonServices.php"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>
 
AmazonServices.php

Code: Select all

 
<?php
 
function AmazonServices($AmazonXMLSchema_rootcomplexType)
  {
 
  $OpType                                               = $XMLFeed->AmazonXMLFeed->MessageType;
  $XMLFeed->AmazonXMLFeed->Header->DocumentVersion      = "2.1";
  $XMLFeed->AmazonXMLFeed->Header->MerchantIdentifier   = "M_STORENAME_8675309";
  $XMLFeed->AmazonXMLFeed->MessageType                  = $OpType;
  $XMLFeed->AmazonXMLFeed->Message->MessageID           = 5684233242;
  $XMLFeed->AmazonXMLFeed->Message->$OpType->SKU        = "8675309";
 
  return("Amazon root complexType XMLFeed");
  } // AmazonServices
 
ini_set("soap.wsdl_cache_enabled", "0");
 
$server = new SoapServer("http://127.0.0.1/Amazon/AmazonServices.wsdl",
                         array('soap_version' => SOAP_1_2,
                               'trace'              => 1,
                               'exceptions'         => 1));
 
$server->addFunction("AmazonServices");
$server->handle();
 
exit();
 
?>
 
AmazonServicesClient.php

Code: Select all

 
<?php
 
$client = new SoapClient("http://127.0.0.1/Amazon/AmazonServices.wsdl",
                         array('soap_version' => SOAP_1_2,
                         'trace'              => 1,
                         'exceptions'         => 1));
 
echo("<p><br/>Dumping client object functions: <br/>");
var_dump($client->__getFunctions());
echo("<br/>");
 
$OpType = "Inventory";
 
$AmazonXMLSchema_rootcomplexType                                            = new StdClass();
$AmazonXMLSchema_rootcomplexType->AmazonXMLFeed                             = new StdClass();
$AmazonXMLSchema_rootcomplexType->AmazonXMLFeed->Header->DocumentVersion    = "1.1";
$AmazonXMLSchema_rootcomplexType->AmazonXMLFeed->Header->MerchantIdentifier = "M_STORENAME_8675309";
$AmazonXMLSchema_rootcomplexType->AmazonXMLFeed->MessageType                = "Inventory";
$AmazonXMLSchema_rootcomplexType->AmazonXMLFeed->Message->MessageID         = 5684233242;
$AmazonXMLSchema_rootcomplexType->AmazonXMLFeed->Message->$OpType->SKU      = "8675309";
 
var_dump($XMLFeed);
 
$XMLFeed = $client->__soapCall("AmazonServices", $AmazonXMLSchema_rootcomplexType);
 
echo("<br/>Returning value of __soapCall() call: <br/>".$return."<br/>");
echo("<br/>Dumping request headers: <br/>".$client->__getLastRequestHeaders()."<br/>");
echo("<br/>Dumping request: </br/>".$client->__getLastRequest()."<br/>");
echo("<br/>Dumping response headers: <br/>".$client->__getLastResponseHeaders()."<br/>");
echo("<br/>Dumping response: <br/>".$client->__getLastResponse()."<br/></p>");
 
exit();
 
?>
 
amzn-envelope.xsd

Code: Select all

 
<?xml version="1.0"?>
<!-- Revision="$Revision: #6 $" -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xsd:include schemaLocation="amzn-base.xsd"/>
    <xsd:include schemaLocation="amzn-header.xsd"/>
    <xsd:include schemaLocation="FulfillmentCenter.xsd"/>
    <xsd:include schemaLocation="Inventory.xsd"/>
    <xsd:include schemaLocation="Listings.xsd"/>
    <xsd:include schemaLocation="OrderAcknowledgement.xsd"/>
    <xsd:include schemaLocation="OrderAdjustment.xsd"/>
    <xsd:include schemaLocation="OrderFulfillment.xsd"/>
    <xsd:include schemaLocation="Override.xsd"/>
    <xsd:include schemaLocation="Price.xsd"/>
    <xsd:include schemaLocation="ProcessingReport.xsd"/>
    <xsd:include schemaLocation="ProductImage.xsd"/>
    <xsd:include schemaLocation="Product.xsd"/>
    <xsd:include schemaLocation="Relationship.xsd"/>
    <xsd:include schemaLocation="SettlementReport.xsd"/>
    <xsd:element name="AmazonEnvelope" type="AmazonXMLEnvelope"/>
    <xsd:complexType name="AmazonXMLEnvelope">
        <xsd:sequence>
            <xsd:element ref="Header"/>
            <xsd:element name="MessageType" type="OpMessageType"/>
            <xsd:element ref="MarketplaceName" minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>
                                            The MarketplaceName is only supported for
                                            Override feeds.
                                            If included here, the MarketplaceName will
                                            apply to all messages in the feed.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="PurgeAndReplace" type="xsd:boolean" minOccurs="0"/>
            <xsd:element name="EffectiveDate" type="xsd:dateTime" minOccurs="0"/>
            <xsd:element name="Message" maxOccurs="unbounded">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="MessageID" type="IDNumber"/>
                        <xsd:element name="OperationType" minOccurs="0">
                            <xsd:simpleType>
                                <xsd:restriction base="xsd:string">
                                    <xsd:enumeration value="Update"/>
                                    <xsd:enumeration value="Delete"/>
                                    <xsd:enumeration value="PartialUpdate"/>
                                </xsd:restriction>
                            </xsd:simpleType>
                        </xsd:element>
                        <xsd:choice>
                            <xsd:element ref="FulfillmentCenter"/>
                            <xsd:element ref="Inventory"/>
                            <xsd:element ref="Listings"/>
                            <xsd:element ref="OrderAcknowledgement"/>
                            <xsd:element ref="OrderAdjustment"/>
                            <xsd:element ref="OrderFulfillment"/>
                            <xsd:element ref="Override"/>
                            <xsd:element ref="Price"/>
                            <xsd:element ref="ProcessingReport"/>
                            <xsd:element ref="Product"/>
                            <xsd:element ref="ProductImage"/>
                            <xsd:element ref="Relationship"/>
                            <xsd:element ref="SettlementReport"/>
                        </xsd:choice>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:simpleType name="OpMessageType">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="FulfillmentCenter"/>
            <xsd:enumeration value="Inventory"/>
            <xsd:enumeration value="Listings"/>
            <xsd:enumeration value="OrderAcknowledgement"/>
            <xsd:enumeration value="OrderAdjustment"/>
            <xsd:enumeration value="OrderFulfillment"/>
            <xsd:enumeration value="Override"/>
            <xsd:enumeration value="Price"/>
            <xsd:enumeration value="ProcessingReport"/>
            <xsd:enumeration value="Product"/>
            <xsd:enumeration value="ProductImage"/>
            <xsd:enumeration value="Relationship"/>
            <xsd:enumeration value="SettlementReport"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:schema>
 
amzn-header.xsd

Code: Select all

 
<?xml version="1.0"?>
<!-- "$Revision: #3 $" -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xsd:include schemaLocation="amzn-base.xsd"/>
    <xsd:element name="Header">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="DocumentVersion">
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:string">
                            <xsd:pattern value="\d{1,2}\.\d{1,2}"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
                <xsd:element name="MerchantIdentifier" type="String"/>
                <xsd:element name="OverrideReleaseId" minOccurs="0">
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:string">
                            <xsd:pattern value="\d{1,4}\.\d{1,4}"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>
 
Inventory.xsd

Code: Select all

 
<?xml version="1.0"?>
<!-- Revision="$Revision: #3 $" -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xsd:include schemaLocation="amzn-base.xsd"/>
    <xsd:element name="Inventory">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="SKU"/>
                <xsd:element ref="FulfillmentCenterID" minOccurs="0"/>
                <xsd:choice>
                    <xsd:element name="Available" type="xsd:boolean"/>
                    <xsd:element name="Quantity" type="xsd:nonNegativeInteger"/>
                    <xsd:element name="Lookup">
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:string">
                                <xsd:enumeration value="FulfillmentNetwork"/>
                            </xsd:restriction>
                        </xsd:simpleType>
                    </xsd:element>
                </xsd:choice>
                <xsd:element name="RestockDate" type="xsd:date" minOccurs="0"/>
                <xsd:element name="FulfillmentLatency" type="xsd:positiveInteger" minOccurs="0"/>
                <xsd:element name="SwitchFulfillmentTo" minOccurs="0">
                    <!-- Use this element if you are switching the 
                            fulfillment method for your item.  
                        If you are switching from AFN to MFN, use "MFN"
                        If you are switching from MFN to AFN, use "AFN"
                    -->
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:string">
                            <xsd:enumeration value="MFN"/>
                            <xsd:enumeration value="AFN"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>
 
Thanks
Post Reply