dounuo1881 2012-03-30 01:19
浏览 63

PHP SOAP服务器是否通过HTTP POST处理请求?

I am trying to set up a web service using php. I have successfully been able to create one using the PHP SOAP extension. However, I want the service to be available through simple HTTP POST and HTTP GET calls. In order to make it simple, I am trying to translate the example at http://www.w3schools.com/webservices/ws_example.asp to be working in a php environment.

The server localhost/tempconvert.php looks like:

<?php
    function CelsiusToFahrenheit($celcius){
        return (((($celcius) * 9) / 5) + 32);
    }

    function FahrenheitToCelsius($fahrenheit){
        return (((($fahrenheit) - 32) / 9) * 5);
    }

    // turn off the wsdl cache
    ini_set("soap.wsdl_cache_enabled", "0");

    $server = new SoapServer("tempconvert.wsdl");

    $server->addFunction("CelsiusToFahrenheit");
    $server->addFunction("FahrenheitToCelsius");

    $server->handle();
?>

and the client localhost/tempclient.php looks like:

<?php
    // turn off the WSDL cache
    ini_set("soap.wsdl_cache_enabled", "0");

    $client = new SoapClient("tempconvert.wsdl");

    $cels = 32;
    $fahr = $client->CelsiusToFahrenheit($cels);

    echo "$cels in fahr is: $fahr";
?>

and finally the wsdl file localhost/tempconvert.wsdl looks like:

<?xml version="1.0" encoding="utf-8"?>
    <wsdl:definitions  
        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
        xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" 
        xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
        xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" 
        xmlns:tns="http://localhost/tempconvert.wdsl" 
        xmlns:s="http://www.w3.org/2001/XMLSchema" 
        xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
        xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
        targetNamespace="http://localhost/tempconvert.wdsl" 
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
      <wsdl:types>
        <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
          <s:element name="FahrenheitToCelsius">
            <s:complexType>
              <s:sequence>
                <s:element minOccurs="0" maxOccurs="1" name="Fahrenheit" type="s:string" />
              </s:sequence>
            </s:complexType>
          </s:element>
          <s:element name="FahrenheitToCelsiusResponse">
            <s:complexType>
              <s:sequence>
                <s:element minOccurs="0" maxOccurs="1" name="FahrenheitToCelsiusResult" type="s:string" />
              </s:sequence>
            </s:complexType>
          </s:element>
          <s:element name="CelsiusToFahrenheit">
            <s:complexType>
              <s:sequence>
                <s:element minOccurs="0" maxOccurs="1" name="Celsius" type="s:string" />
              </s:sequence>
            </s:complexType>
          </s:element>
          <s:element name="CelsiusToFahrenheitResponse">
            <s:complexType>
              <s:sequence>
                <s:element minOccurs="0" maxOccurs="1" name="CelsiusToFahrenheitResult" type="s:string" />
              </s:sequence>
            </s:complexType>
          </s:element>
          <s:element name="string" nillable="true" type="s:string" />
        </s:schema>
      </wsdl:types>
      <wsdl:message name="FahrenheitToCelsiusSoapIn">
        <wsdl:part name="parameters" element="tns:FahrenheitToCelsius" />
      </wsdl:message>
      <wsdl:message name="FahrenheitToCelsiusSoapOut">
        <wsdl:part name="parameters" element="tns:FahrenheitToCelsiusResponse" />
      </wsdl:message>
      <wsdl:message name="CelsiusToFahrenheitSoapIn">
        <wsdl:part name="parameters" element="tns:CelsiusToFahrenheit" />
      </wsdl:message>
      <wsdl:message name="CelsiusToFahrenheitSoapOut">
        <wsdl:part name="parameters" element="tns:CelsiusToFahrenheitResponse" />
      </wsdl:message>
      <wsdl:message name="FahrenheitToCelsiusHttpPostIn">
        <wsdl:part name="Fahrenheit" type="s:string" />
      </wsdl:message>
      <wsdl:message name="FahrenheitToCelsiusHttpPostOut">
        <wsdl:part name="Body" element="tns:string" />
      </wsdl:message>
      <wsdl:message name="CelsiusToFahrenheitHttpPostIn">
        <wsdl:part name="Celsius" type="s:string" />
      </wsdl:message>
      <wsdl:message name="CelsiusToFahrenheitHttpPostOut">
        <wsdl:part name="Body" element="tns:string" />
      </wsdl:message>
      <wsdl:portType name="TempConvertSoap">
        <wsdl:operation name="FahrenheitToCelsius">
          <wsdl:input message="tns:FahrenheitToCelsiusSoapIn" />
          <wsdl:output message="tns:FahrenheitToCelsiusSoapOut" />
        </wsdl:operation>
        <wsdl:operation name="CelsiusToFahrenheit">
          <wsdl:input message="tns:CelsiusToFahrenheitSoapIn" />
          <wsdl:output message="tns:CelsiusToFahrenheitSoapOut" />
        </wsdl:operation>
      </wsdl:portType>
      <wsdl:portType name="TempConvertHttpPost">
        <wsdl:operation name="FahrenheitToCelsius">
          <wsdl:input message="tns:FahrenheitToCelsiusHttpPostIn" />
          <wsdl:output message="tns:FahrenheitToCelsiusHttpPostOut" />
        </wsdl:operation>
        <wsdl:operation name="CelsiusToFahrenheit">
          <wsdl:input message="tns:CelsiusToFahrenheitHttpPostIn" />
          <wsdl:output message="tns:CelsiusToFahrenheitHttpPostOut" />
        </wsdl:operation>
      </wsdl:portType>
      <wsdl:binding name="TempConvertSoap" type="tns:TempConvertSoap">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="FahrenheitToCelsius">
          <soap:operation soapAction="http://tempuri.org/FahrenheitToCelsius" style="document" />
          <wsdl:input>
            <soap:body use="literal" />
          </wsdl:input>
          <wsdl:output>
            <soap:body use="literal" />
          </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="CelsiusToFahrenheit">
          <soap:operation soapAction="http://tempuri.org/CelsiusToFahrenheit" style="document" />
          <wsdl:input>
            <soap:body use="literal" />
          </wsdl:input>
          <wsdl:output>
            <soap:body use="literal" />
          </wsdl:output>
        </wsdl:operation>
      </wsdl:binding>
      <wsdl:binding name="TempConvertSoap12" type="tns:TempConvertSoap">
        <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="FahrenheitToCelsius">
          <soap12:operation soapAction="http://tempuri.org/FahrenheitToCelsius" style="document" />
          <wsdl:input>
            <soap12:body use="literal" />
          </wsdl:input>
          <wsdl:output>
            <soap12:body use="literal" />
          </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="CelsiusToFahrenheit">
          <soap12:operation soapAction="http://tempuri.org/CelsiusToFahrenheit" style="document" />
          <wsdl:input>
            <soap12:body use="literal" />
          </wsdl:input>
          <wsdl:output>
            <soap12:body use="literal" />
          </wsdl:output>
        </wsdl:operation>
      </wsdl:binding>
      <wsdl:binding name="TempConvertHttpPost" type="tns:TempConvertHttpPost">
        <http:binding verb="POST" />
        <wsdl:operation name="FahrenheitToCelsius">
          <http:operation location="/FahrenheitToCelsius" />
          <wsdl:input>
            <mime:content type="application/x-www-form-urlencoded" />
          </wsdl:input>
          <wsdl:output>
            <mime:mimeXml part="Body" />
          </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="CelsiusToFahrenheit">
          <http:operation location="/CelsiusToFahrenheit" />
          <wsdl:input>
            <mime:content type="application/x-www-form-urlencoded" />
          </wsdl:input>
          <wsdl:output>
            <mime:mimeXml part="Body" />
          </wsdl:output>
        </wsdl:operation>
      </wsdl:binding>
      <wsdl:service name="TempConvert">
        <wsdl:port name="TempConvertSoap" binding="tns:TempConvertSoap">
          <soap:address location="http://localhost/tempconvert.php" />
        </wsdl:port>
        <wsdl:port name="TempConvertSoap12" binding="tns:TempConvertSoap12">
          <soap12:address location="http://localhost/tempconvert.php" />
        </wsdl:port>
        <wsdl:port name="TempConvertHttpPost" binding="tns:TempConvertHttpPost">
          <http:address location="http://localhost/tempconvert.php" />
        </wsdl:port>
      </wsdl:service>
    </wsdl:definitions>

Using the client works fine and output the corrent result. Calling the server using localhost/tempconvert.php?WSDL outputs the wsdl content.

However, calling the server localhost/tempcovert.php using the HTTP POST port with the payload Celsius=100 does not work and gives a HTTP error 500 response?

Shouldn't the SOAP extension functionality take care of this?

...or do I have to add functionality in the server file myself? (like using: if ($_POST) ...)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端