Daniel Gadawski
Daniel Gadawski

Reputation: 1923

SOAP-ERROR: Parsing Schema: can't import schema. Namespace must not match the enclosing schema 'targetNamespace'

I need to run SOAP server using Zend_Soap_Server and WSDL prepared before. However, when I try to do it with:

$server = new Zend_Soap_Server($wsdlUrl);
$server->setClass('Logic_WebService_Test');
$server->handle();

I get an error:

SOAP-ERROR: Parsing Schema: can't import schema. Namespace must not match the enclosing schema 'targetNamespace'

Here's my WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<!-- version="1.0" comment="" -->
<wsdl:definitions
    targetNamespace="http://ws.orange.pl/mo-sms-service-ws"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:apachesoap="http://xml.apache.org/xml-soap"
    xmlns:impl="http://ws.orange.pl/mo-sms-service-ws"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
        ------------------------------------------------------------------------------------------
        Contract interface documentation
        --------------------------------
        Document release: V1_0
        Author (entity): AMG.net
        Creation date: 01/10/2013
        Description: mo-sms-service-ws contract interface
        ------------------------------------------------------------------------------------------
        Changes history
        ---------------
        Version Date Comments
        V1_0 01/10/2013 WSDL contract
        ------------------------------------------------------------------------------------------
    </wsdl:documentation>
    <wsdl:types>
        <schema elementFormDefault="qualified"
            targetNamespace="http://ws.orange.pl/mo-sms-service-ws"
            xmlns="http://www.w3.org/2001/XMLSchema"
            xmlns:apachesoap="http://xml.apache.org/xml-soap"
            xmlns:impl="http://ws.orange.pl/mo-sms-service-ws"
            xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

            <xsd:import namespace="http://ws.orange.pl/mo-sms-service-ws" />
            <element name="DeliverShortMessage">
                <complexType>
                    <sequence>
                        <element name="sms" type="impl:SMSMessage" />
                    </sequence>
                </complexType>
            </element>
            <element name="DeliverShortMessageResponse">
                <complexType>
                    <sequence>
                        <element name="DeliverShortMessageReturn" nillable="true" type="xsd:boolean" />
                    </sequence>
                </complexType>
            </element>
            <element name="DeliverNotification">
                <complexType>
                    <sequence>
                        <element name="sms" type="impl:SMSNotification" />
                    </sequence>
                </complexType>
            </element>
            <element name="DeliverNotificationResponse">
                <complexType>
                    <sequence>
                        <element name="DeliverNotificationReturn" nillable="true" type="xsd:boolean" />
                    </sequence>
                </complexType>
            </element>
        </schema>
        <schema elementFormDefault="qualified"
            targetNamespace="http://ws.orange.pl/mo-sms-service-ws"
            xmlns="http://www.w3.org/2001/XMLSchema"
            xmlns:apachesoap="http://xml.apache.org/xml-soap"
            xmlns:impl="http://ws.orange.pl/mo-sms-service-ws"
            xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
            <complexType name="SMSMessage">
                <sequence>
                    <element name="recipient" minOccurs="1" type="xsd:string" />
                    <element name="recipientAlias" minOccurs="0" type="xsd:string" />
                    <element name="originator" minOccurs="1" type="xsd:string" />
                    <element name="content" minOccurs="1" type="xsd:string" />
                    <element name="transactionId" minOccurs="1" type="xsd:string" />
                    <element name="timestamp" minOccurs="0" type="xsd:string" />
                </sequence>
            </complexType>
            <complexType name="SMSNotification">
                <sequence>
                    <element name="recipient" minOccurs="0" type="xsd:string" />
                    <element name="originator" minOccurs="0" type="xsd:string" />
                    <element name="transactionId" minOccurs="1" type="xsd:string" />
                    <element name="status" minOccurs="1" type="xsd:string" />
                    <element name="errorCode" minOccurs="0" type="xsd:string" />
                    <element name="content" minOccurs="0" type="xsd:string" />
                    <element name="timestamp" minOccurs="0" type="xsd:string" />
                </sequence>
            </complexType>
        </schema>
    </wsdl:types>
    <wsdl:message name="DeliverShortMessageRequest">
        <wsdl:part element="impl:DeliverShortMessage" name="parameters" />
    </wsdl:message>
    <wsdl:message name="DeliverShortMessageResponse">
        <wsdl:part element="impl:DeliverShortMessageResponse" name="parameters" />
    </wsdl:message>
    <wsdl:message name="DeliverNotificationRequest">
        <wsdl:part element="impl:DeliverNotification" name="parameters" />
    </wsdl:message>
    <wsdl:message name="DeliverNotificationResponse">
        <wsdl:part element="impl:DeliverNotificationResponse" name="parameters" />
    </wsdl:message>
    <wsdl:portType name="MoSmsServiceWs">
        <wsdl:operation name="DeliverShortMessage">
            <wsdl:input message="impl:DeliverShortMessageRequest" name="DeliverShortMessageRequest" />
            <wsdl:output message="impl:DeliverShortMessageResponse" name="DeliverShortMessageResponse" />
        </wsdl:operation>
        <wsdl:operation name="DeliverNotification">
            <wsdl:input message="impl:DeliverNotificationRequest" name="DeliverNotificationRequest" />
            <wsdl:output message="impl:DeliverNotificationResponse" name="DeliverNotificationResponse" />
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="MoSmsServiceWsSoapBinding" type="impl:MoSmsServiceWs">
        <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="DeliverShortMessage">
            <wsdlsoap:operation soapAction="http://ws.orange.pl/mo-sms-service-ws/delivershortmessage" />
            <wsdl:input name="DeliverShortMessageRequest">
                <wsdlsoap:body use="literal" />
            </wsdl:input>
            <wsdl:output name="DeliverShortMessageResponse">
                <wsdlsoap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="DeliverNotification">
            <wsdlsoap:operation soapAction="http://ws.orange.pl/mo-sms-service-ws/delivernotification" />
            <wsdl:input name="DeliverNotificationRequest">
                <wsdlsoap:body use="literal" />
            </wsdl:input>
            <wsdl:output name="DeliverNotificationResponse">
                <wsdlsoap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="MoSmsService">
        <wsdl:port binding="impl:MoSmsServiceWsSoapBinding" name="MoSmsServiceWs">
            <wsdlsoap:address location="http://ws.orange.pl/mo-sms-service-ws/MoSmsServiceWs" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

What's wrong with it?

Upvotes: 2

Views: 4927

Answers (2)

Joman68
Joman68

Reputation: 2850

To see the official documentation on this restriction: https://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#element-import

Specifically clause 1.1 below:

Schema Representation Constraint: Import Constraints and Semantics

In addition to the conditions imposed on <import> element information items by the schema for schemas all of the following must be true:
    1 The appropriate case among the following must be true:
        1.1 If the namespace [attribute] is present, then its ·actual value· must not match the ·actual value· of the enclosing <schema>'s targetNamespace [attribute].
        1.2 If the namespace [attribute] is not present, then the enclosing <schema> must have a targetNamespace [attribute]

One solution is to use <xsd:include .../> rather than <xsd:import .../>. See https://www.w3.org/TR/xmlschema-0/#ref23

The one important caveat to using include is that the target namespace of the included components must be the same as the target namespace of the including schema

See also: https://stackoverflow.com/a/2357988/3059685

Upvotes: 1

Daniel Gadawski
Daniel Gadawski

Reputation: 1923

Problem was in this line:

<xsd:import namespace="http://ws.orange.pl/mo-sms-service-ws" />

It tries to import recursively namespace "http://ws.orange.pl/mo-sms-service-ws", which is not handled by PHP.

In my case, removing of this line helped.

Upvotes: 2

Related Questions