我正在创建一个SOAP服务,但我不给它。
我有这些文件
server.php
<?php
ini_set("soap.wsdl_cache_enabled","0");
function simpleFunction() {
return 'simpleFunction';
}
// initialize SOAP Server
$server=new SoapServer("simple.wsdl");
$server->addFunction('simpleFunction');
$server->handle();
&
simple.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="Simple"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="Simple"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="Simple"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:message name="simpleFunctionRequest">
<wsdl:part name="in1" type="xsd:string"></wsdl:part>
<wsdl:part name="in2" type="xsd:string"></wsdl:part>
</wsdl:message>
<wsdl:message name="simpleFunctionResponse">
<wsdl:part name="out1" type="tns:integer"></wsdl:part>
<wsdl:part name="out2" type="xsd:string"></wsdl:part>
</wsdl:message>
<wsdl:portType name="Simple">
<wsdl:operation name="simpleFunction">
<wsdl:input message="tns:simpleFunctionRequest"/>
<wsdl:output message="tns:simpleFunctionResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Simple" type="tns:Simple">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="simpleFunction">
<soap:operation
soapAction="http://192.168.56.2/ws/verySimple/server.php"/>
<wsdl:input>
<soap:body use="literal" namespace="Simple"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal" namespace="Simple"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Simple">
<wsdl:port binding="tns:Simple" name="Simple">
<soap:address
location="http://192.168.56.2/ws/verySimple/server.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
为了证明这一点,我创建了这个客户端
client.php
<?php
$in1='in1';
$in2='in2';
$client=new SoapClient('simple.wsdl',
['trace'=>1,'cache_wsdl'=>WSDL_CACHE_NONE]);
$resp =$client->simpleFunction($in1, $in2);
// dump response
var_dump($resp);
我已经在 XAMP 中启动了一个服务器,如果我调用客户端.php它会返回以下内容:
array (2) {["out1"] => NULL ["out2"] => NULL}
我还尝试使用SoapUI使用url进行项目
的服务http: //localhost/verySimple/simple.wsdl
并给了我一个简单功能的请求
<soapenv: Envelope xmlns: soapenv =
"http://schemas.xmlsoap.org/soap/envelope/" xmlns: sim = "Simple">
<soapenv: Header />
<soapenv: Body>
<sim: simpleFunction>
<in1>? </ in1>
<in2>? </ in2>
</ sim: simpleFunction>
</ soapenv: Body>
</ soapenv: Envelope>
和响应
<SOAP-ENV: Envelope xmlns: SOAP-ENV = "http://schemas.xmlsoap.org/soap/envelope/" xmlns: ns1 = "Simple">
<SOAP-ENV: Body>
<ns1: simpleFunctionResponse />
</ SOAP-ENV: Body>
</ SOAP-ENV: Envelope>
如果我将相同的服务(将 url 从 http://localhost 更改为 http://192.168.56.2/ws/)复制到虚拟机中的另一台服务器
我打电话给客户.php它没有向我显示任何东西
如果我使用 SoapUi 来对抗 http://192.168.56.2/ws/verySimple/simple.wsdl
请求返回
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"xmlns:sim="Simple">
<soapenv:Header/>
<soapenv:Body>
<sim:simpleFunction>
<in1>?</in1>
<in2>?</in2>
</sim:simpleFunction>
</soapenv:Body>
</soapenv:Envelope>
但是没有回应...
我想问题是配置第二台服务器,但我不知道我必须做什么才能响应。你可以帮我吗?
奖金问题:-):
在本地主机中,
var_dump($resp);
是
array (2) {["out1"] => NULL ["out2"] => NULL}
但我不知道如何填充这个数组,因为函数
return 'simpleFunction';
但我不知道这个字符串在哪里:-(
您已将函数的响应定义为如下所示的类型:
class simpleFunctionResponse {
public $out1;
public $out2;
}
但该函数实际上返回一个字符串。
尝试类似操作:
// Using the class defined above
function simpleFunction() {
return new simpleFunctionResponse();
}
// or just with an array
function simpleFunction() {
return array(
'out1' => 1,
'out2' => 'my string',
);
}