为hello world soapserver生成WSDL文件
问题描述:
我在为我的hellowold PHP soapserver创建WSDL文件时遇到了麻烦。为hello world soapserver生成WSDL文件
Server代码:
<?php
function hello($soapData) {
$finalresponse [] = new SoapVar ($soapData->name, XSD_STRING, null, null, 'content');
$finalresponse [] = new SoapVar ("1980-01-01", XSD_DATE, null, null, 'endDate');
$finalresponse [] = new SoapVar ("1980-01-01", XSD_DATE, null, null, 'startDate');
return new SoapVar ($finalresponse, SOAP_ENC_OBJECT, null, null, "");
}
ini_set ("soap.wsdl_cache_enabled", "0");
$server = new SoapServer ("http://example.com:8080/wsdl.wsdl", array ('soap_version' => SOAP_1_2));
$server->addFunction ("hello");
$server->handle();
?>
WSDL.file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<definitions xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://example.com:8083/wsdl.php" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:foo" xmlns:S2="urn:foo:bar" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="hello" targetNamespace="urn:foo">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="urn:foo:bar">
<element name="dataSet">
<complexType>
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="hello">
<complexType>
<sequence>
<element name="hello" nillable="true" type="xsd:string"/>
<element name="date" nillable="true" type="xsd:date"/>
</sequence>
</complexType>
</element>
</sequence>
</complexType>
</element>
<element name="hello">
<complexType>
<sequence>
<element name="name" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="helloResponse">
<complexType>
<sequence>
<element ref="S2:dataSet"/>
</sequence>
</complexType>
</element>
</schema>
</types>
<message name="hello_hello">
<part name="parameters" element="S2:hello"/>
</message>
<message name="hello_helloResponse">
<part name="parameters" element="S2:helloResponse"/>
</message>
<portType name="helloObj">
<operation name="hello">
<input message="tns:hello_hello"/>
<output message="tns:hello_helloResponse"/>
</operation>
</portType>
<binding name="helloObj" type="tns:helloObj">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="hello">
<soap:operation soapAction="" style="document"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="helloService">
<port name="helloObj" binding="tns:helloObj">
<wsdl:documentation/>
<soap:address location="http://example.com:8083/wsdl.php"/>
</port>
</service>
</definitions>
我有那样的工作,直到你尝试验证他们对WSDL文件成功使SOAP服务器。我的目标是创建一个非常基本的“Hello World”示例,并验证WSDL文件。
的soapUI是给我的错误:
line 4: Expected element '[email protected]:foo:bar' instead of 'dataSet' here in element [email protected]:foo:bar line 7: Expected element '[email protected]:foo:bar' before the end of the content in element [email protected]:foo:bar
如何更新WSDL文件,这样我没有得到这个错误。
谢谢。
答
如果有人绊倒这个问题。请浏览这个IBM站点,它是一个小技术,但它具有您可能需要的所有基本信息,以开始使用SOAP和WSDL文件。 Web Services Description Language (WSDL)
我相信下面的WSDL可以作出更好,但它的工作原理(在.NET验证)
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:tns="http://ws.apache.org/axis2" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://ws.apache.org/axis2">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://org.apache.axis2/xsd" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:element name="helloRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="name" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="helloResponse">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="content" />
<xs:element type="xs:date" name="endDate" />
<xs:element type="xs:date" name="startDate" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="helloRequestMessage">
<wsdl:part name="part1" element="ns1:helloRequest"/>
</wsdl:message>
<wsdl:message name="helloResponseMessage">
<wsdl:part name="part1" element="ns1:helloResponse"/>
</wsdl:message>
<wsdl:portType name="helloPortType">
<wsdl:operation name="hello">
<wsdl:input message="tns:helloRequestMessage"/>
<wsdl:output message="tns:helloResponseMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="helloBinding" type="tns:helloPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
<wsdl:operation name="hello">
<soap:operation soapAction="hello" style="document" />
<wsdl:input>
<soap:body use="literal"
namespace="http://example.com:8080/wsdl.php" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal"
namespace="http://example.com:8080/wsdl.php" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="helloService">
<wsdl:port name="helloPort" binding="tns:helloBinding">
<soap:address location="http://example.com:8080/wsdl.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>