我正在创建一个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>但没有回应..。
我想问题是配置第二台服务器,但我不知道要做什么才能做出响应。你能帮帮我吗?
奖金问题:-):
在本地宿主中,
var_dump($resp); 是
array (2) {["out1"] => NULL ["out2"] => NULL} 但我不知道如何填充这个数组因为函数
return 'simpleFunction'; 但我不知道这条绳子在哪里
发布于 2018-03-15 09:58:08
您已经将函数的响应定义为如下类型:
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',
);
}https://stackoverflow.com/questions/49277202
复制相似问题