gpt4 book ai didi

PHP SOAP : Communication to a C++ application

转载 作者:太空宇宙 更新时间:2023-11-04 14:19:46 25 4
gpt4 key购买 nike

我有一个使用 gSOAP 的 C++ SOAP 客户端并试图构建一个非常简单的 PHP 服务器(Debian 上的 Apache2/PHP5),客户端可以与之通信。不幸的是,我不明白如何处理我的 Web 服务在 PHP 中使用的复杂类型。

我有一个看起来像这样的 .wsdl:

<definitions name="NumOps"
targetNamespace="http://192.168.2.113/numops.wsdl"
xmlns:tns="http://192.168.2.113/numops.wsdl"
xmlns:xsd1="http://192.168.2.113/testtypes.xsd"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/">

<types>
<schema targetNamespace="http://192.168.2.113/testtypes.xsd"
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="AddValRequest">
<complexType>
<all>
<element name="fVal1" type="float"/>
<element name="fVal2" type="float"/>
</all>
</complexType>
</element>
<element name="AddValResponse">
<complexType>
<all>
<element name="fResult" type="float"/>
</all>
</complexType>
</element>
</schema>
</types>

<message name="AddValInput">
<part name="body" element="xsd1:AddValRequest"/>
</message>
<message name="AddValOutput">
<part name="body" element="xsd1:AddValResponse"/>
</message>

<portType name="NumOpsPortType">
<operation name="AddVal">
<input message="tns:AddValInput"/>
<output message="tns:AddValOutput"/>
</operation>
</portType>

<binding name="NumOpsSoapProxy" type="tns:NumOpsPortType">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="AddVal">
<soap:operation soapAction="http://192.168.2.113/"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>

<service name="NumOpsService">
<port name="NumOpsPort" binding="tns:NumOpsSoapProxy">
<soap:address location="http://192.168.2.113/"/>
</port>
</service>

</definitions>

我目前的做法是这样的:

<?php

function AddVal($AddValRequest) {
// How to create a AddValResponse?!
}

$server = new SoapServer(NULL, array("uri"=>"http://192.168.2.113/"));
$server->addFunction("AddVal");
$server->handle();

?>

这里的问题是我没有任何东西可以让我开始做这件事,而且我可能无法解决这个猜测。有谁知道我在哪里可以找到 Material 来深入研究这个问题?

最佳答案

这有效:

class AddValRequest {
public $fVal1;
public $fVal2;
}

class AddValResponse {
public $fResult;
}

function AddVal(AddValRequest $request) {
$response = new AddValResponse();
$response->fResult = $request->fVal1 + $request->fVal2;
return $response;
}

$server = new SoapServer("numops.wsdl");
$server->addFunction("AddVal");
$server->handle();

?>

应该足以让遇到同样问题的人开始。

关于PHP SOAP : Communication to a C++ application,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8541070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com