WSDL + SOAP + PHP返回值

时间:2011-10-24 04:06:04

标签: php soap wsdl

抱歉文本布局不好,这是wsdl文件

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="test"
 targetNamespace="test"
 xmlns:tns="test"
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:test="test"
xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:MIME="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:DIME="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/"
xmlns:WSDL="http://schemas.xmlsoap.org/wsdl/"
 xmlns="http://schemas.xmlsoap.org/wsdl/"> 
<types> 
 <schema targetNamespace="test"
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:test="test"
 xmlns="http://www.w3.org/2001/XMLSchema"
 elementFormDefault="qualified"
 attributeFormDefault="unqualified">
  <import namespace="http://schemas.xmlsoap.org/soap/encoding/"        schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/>
 <!-- operation request element -->
 <element name="getMobile">
 <complexType>
   <sequence>
 <element name="user" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
 </sequence>
  </complexType>
 </element>
 <!-- operation response element -->
  <element name="getMobileResponse">
 <complexType>
  <sequence>
  <element name="phone-num" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
  </sequence>
 </complexType>
</element>
</schema> 
    </types> 
  <message name="getMobileRequest">
   <part name="parameters" element="test:getMobile"/>
 </message> 
 <message name="getMobileResponse">
 <part name="parameters" element="test:getMobileResponse"/>
 </message> 
 <portType name="testPortType">
 <operation name="getMobile">
  <documentation>Service definition of function test__getMobile</documentation>
  <input message="tns:getMobileRequest"/>
 <output message="tns:getMobileResponse"/>
 </operation>
 </portType> 
 <binding name="test" type="tns:testPortType">
 <SOAP:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
 <operation name="getMobile">
 <SOAP:operation soapAction=""/>
  <input>
 <SOAP:body parts="parameters" use="literal"/>
  </input>
  <output>
  <SOAP:body parts="parameters" use="literal"/>
 </output>
   </operation>
   </binding> 
   <service name="test">
   <documentation>gSOAP 2.7.12 generated service definition</documentation>
   <port name="test" binding="tns:test">
   <SOAP:address location="http://192.168.82.59:35088"/>
   </port>
  </service> 
  </definitions>

C ++函数get mobile是从客户端读取用户输入的人名,并返回手机号码。 例如用户输入Grace,并返回123456。

我应该在php文件中添加什么,硬编码用户输入总是为“Grace”,并且应该在屏幕上返回12345。 我把下面的代码放到php中,但我只有

   Notice: Undefined variable: x in C:\xampp\htdocs\soaptest\test.php on line 6 
    Fatal error: Call to a member function getMobile() on a non-object in C:\xampp\htdocs  \soaptest\test.php on line 6
<?php
try { 
ini_set("soap.wsdl_cache_enabled", "0");
$x = @new SoapClient("test.wsdl"); 
 } catch (Exception $e) { 
var_dump(  $x ->getMobile( 'Grace' ) ) ;
}
?> 

现在我得到了这个

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing Schema: can't  
import schema from 'http://schemas.xmlsoap.org/soap/encoding/' in C:\xampp\htdocs
\soaptest\test.php:3 Stack trace: #0 C:\xampp\htdocs\soaptest\test.php(3): 
SoapClient->SoapClient('test.wsdl') #1 {main} thrown in C:\xampp\htdocs\soaptest
\test.php on line 3

修改我的PHP代码后

<?php
$wsdl_url='test.wsdl';
$client = new SoapClient($wsdl_url);
$country = array( "user" => "Grace");
$quote=$client->getMobile($country);
print $quote; 
?> 

0 个答案:

没有答案