PHP SOAP:与c++应用程序的通信

PHP SOAP: Communication to a C++ application

本文关键字:应用程序 通信 c++ SOAP PHP      更新时间:2023-10-16

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

我有一个。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();
?>

这里的问题是,我没有任何东西可以让我开始,我可能不会解决这个猜测。有人知道我在哪里可以找到材料来深入研究这件事吗?

这行得通:

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();
?>

,应该足以让有同样问题的人开始。