wsdl:import要素を定義することで,ほかのWSDLファイルをインポートできます。
WSDLのインポートの概念を次の図に示します。
図3-16 WSDLのインポート
wsdl:import要素の書式と属性を示します。
<wsdl:import namespace="インポート対象の名前空間のURI"
location="インポート対象のWSDLのファイル名"/>
wsdl:import要素の構文,および定義時の注意事項を示します。
WSDLをインポートする場合,インポート元またはインポート対象のどちらかのWSDLに,wsdl:binding要素を定義する必要があります。次の表に,WSDLをインポートする場合に定義が必要な要素の組み合わせを示します。
表3-8 WSDLをインポートする場合の要素の組み合わせ
インポート元 | インポート対象 |
---|---|
wsdl:binding wsdl:service | wsdl:types※ wsdl:message wsdl:portType |
wsdl:service | wsdl:types※ wsdl:message wsdl:portType wsdl:binding |
wsdl:import要素は,次に示す規則に従って記述してください。
インポート対象のWSDLでは,ルート要素をwsdl:definitions要素にしてください。また,インポート対象のwsdl:definitions要素のtargetNamespace属性は,次に示す規則に従って記述してください。
wsdl:definitionsの子要素にwsdl:import要素を複数行記述することで,複数のWSDLをインポートできます。ただし,インポート対象のWSDLで名前空間(namespace属性の値)またはファイル名(location属性の値)のどちらかが重複した場合は,インポートできません。
WSDLをインポートする場合の定義例を示します。
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://service.dictionary.com"
xmlns:intf="http://dictionary.com"
xmlns:svc="http://service.dictionary.com"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:import namespace="http://dictionary.com" location="DataInfo.wsdl"/>
<wsdl:binding name="DataInfoSoapBinding" type="intf:DataInfo">
...
</wsdl:binding>
<wsdl:service name="DataInfoService">
...
</wsdl:service>
</wsdl:definitions>
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://dictionary.com"
xmlns:intf="http://dictionary.com"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
...
</wsdl:types>
<wsdl:message name="getDataResponse">
...
</wsdl:message>
<wsdl:portType name="DataInfo">
...
</wsdl:portType>
</wsdl:definitions>