我正在创建一个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中启动了一个服务器,如果我调用client.php它会返回:
array (2) {["out1"] => NULL ["out2"] => NULL}
我也尝试使用SoapUI使用url
执行项目的服务http: //localhost/verySimple/simple.wsdl
并给我一个SimpleFuntion请求
<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/)到我在虚拟机中的另一台服务器
我打电话给client.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>
但没有回应...
我想问题是配置第二台服务器,但我不知道我要做什么回应。你能救我吗?
奖金问题: - ):
在localhost中
var_dump($resp);
是
array (2) {["out1"] => NULL ["out2"] => NULL}
但我不知道如何填充这个数组因为函数
return 'simpleFunction';
但我不知道这个字符串在哪里: - (
答案 0 :(得分:1)
您已将函数的响应定义为这样的类型:
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',
);
}