Php中的WSDL Api
我想在PHP中开发WSDL服务 我创建了一个PHP文件Php中的WSDL Api,php,web-services,soap,Php,Web Services,Soap,我想在PHP中开发WSDL服务 我创建了一个PHP文件index.PHP,我通过SOAP调用了hello.wsdl文件 代码如下: <?php $client = new soapclient('`http://localhost/test/hello.wsdl`'); $response=$client->addSubscriber('EMtest', 44983, 'name@example.com', 'Name'); ech
index.PHP
,我通过SOAP调用了hello.wsdl
文件
代码如下:
<?php
$client = new soapclient('`http://localhost/test/hello.wsdl`');
$response=$client->addSubscriber('EMtest', 44983, 'name@example.com', 'Name');
echo $response;
?>
<?xml version="1.0"?>
<definitions name="MyDefinition"
targetNamespace="urn:myTargetNamespace"
xmlns:tns="urn:myTns"
xmlns:xsd="`http://www.w3.org/2001/XMLSchema`"
xmlns:soap="`http://schemas.xmlsoap.org/wsdl/soap/`"
xmlns="`http://schemas.xmlsoap.org/wsdl/`">
<message name="addSubscriberRequest">
<part name="api_key" type="xsd:string"/>
<part name="group_id" type="xsd:int"/>
<part name="email" type="xsd:string"/>
<part name="name" type="xsd:string"/>
</message>
<message name="addSubscriberResponse">
<part name="error" type="tns:ErrorTypeEnum"/>
</message>
<operation name="addSubscriber
">
<input message="tns:addSubscriberRequest"/>
<output message="tns:addSubscriberResponse"/>
但我无法获得soap请求响应。。。
我有一些错误,比如:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from '`http://localhost/test/hello.php?wsdl`' : Start tag expected, '<' not found in /var/www/test/index.php:39 Stack trace: #0 /var/www/test/index.php(39): SoapClient->SoapClient('`http://localhost...`') #1 {main} thrown in /var/www/test/index.php on line 39
致命错误:未捕获的SoapFault异常:[WSDL]SOAP-error:解析WSDL:无法从加载'`http://localhost/test/hello.php?wsdl`“:需要开始标记,”您的WSDL不完整,还有很多工作要做。我建议您首先开始使用XSD对请求和响应操作进行建模,然后将该XSD导入WSDL并从那里使用它
您需要一个像样的WSDL编辑器,如AltovaXMLSpy或LiquidXMLStudio。下面是一个示例,说明您的最小WSDL需要是什么样子。我建议您将此骨架与您的骨架进行比较,并了解其中的差异
您缺少的是:
- 关于传递给这些操作的请求、响应和对象的模式(XSD)信息
- 端口定义
- 服务定义
- 绑定
如果您真的想使用web服务,那么理解这些基本概念是至关重要的。我建议您先了解这些概念,然后在遇到我们可以解决的具体问题时再回来
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions name="Hello"
targetNamespace="http://mycompanyurl.com/HelloService_v1"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="http://mycompanyurl.com/HelloService_v1"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xs:schema elementFormDefault="qualified"
targetNamespace="http://example.com/">
<xs:element name="InputType">
<xs:complexType>
<xs:sequence>
<xs:element name="input"
type="string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="OutputType">
<xs:complexType>
<xs:sequence>
<xs:element name="output"
type="string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="addSubscriberRequest">
<wsdl:part name="InputMessagePart"
element="tns:InputType" />
</wsdl:message>
<wsdl:message name="addSubscriberResponse">
<wsdl:part name="OutputMessagePart"
element="tns:OutputType" />
</wsdl:message>
<wsdl:portType name="HelloServicePortType">
<wsdl:operation name="addSubscriber">
<wsdl:input message="tns:addSubscriberRequest" />
<wsdl:output message="tns:addSubscriberResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloHTTPBinding"
type="tns:HelloServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document" />
<wsdl:operation name="addSubscriber">
<wsdl:input />
<wsdl:output />
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloService">
<wsdl:port name="HelloPort"
binding="tns:HelloHTTPBinding">
<soap:address location="http://mycompanyurl.helloservice.com" />
</wsdl:port>
</wsdl:service>