dongmeba4877 2013-09-06 09:26
浏览 211

错误SoapFault异常:[HTTP]禁止

Help me please to solve this problem. I just want to test this example web service.

error:

3 add 4 = SoapFault exception: [HTTP] Forbidden in .....soap-client-2.php:14 Stack trace: #0 [internal function]: SoapClient->_doRequest('_call('getResult', Array) #2 ............/soap-client-2.php(14): SoapClient->getResult('add', 3, 4) #3 {main}

Client:

<?php
phpinfo();
    // Désactivation du cache WSDL
    ini_set("soap.wsdl_cache_enabled", "0");  

    $options = array("trace" => true);

  $client = new SoapClient("operation.wsdl", $options); 
  try { 
    $operation = "add";
    $integer1  = 3;
    $integer2  = 4;
    echo "$integer1 $operation $integer2 = ";
    echo $client->getResult($operation, $integer1, $integer2); 
    print "<pre>
"; 
      print "Request :
".htmlspecialchars($client->__getLastRequest()) ."
"; 
      print "Response:
".htmlspecialchars($client->__getLastResponse())."
"; 
      print "</pre>"; 
  } catch (SoapFault $exception) { 
    echo $exception;       
  } 
?>

server

<?php
/*
 * Fonction getResult sert à addition ou soustraire 2 entiers et retourne le résultat
 * @param $operation Type de l'opération (add/substract)
 * @param $integer1 Entier 1
 * @param $integer2 Entier 2
 * @return $result Résultat de l'opération
 */
function getResult($operation, $integer1, $integer2) {
    $result = 0;

    if (($operation != "add") && ($operation != "substract")) {
      throw new SoapFault("Server", "Veuillez utiliser une methode d'operation valable (add/substract).");
    } 
    if (!$integer1 || !$integer2) {
      throw new SoapFault("Server", "Veuillez indiquer 2 entiers.");
    } 
    if ($operation == "add") {
      $result = $integer1 + $integer2;
    }
    if ($operation == "substract") {
      $result = $integer1 -$integer2;
    }

    return $result; 
}  

// Désactivation du cache WSDL
ini_set("soap.wsdl_cache_enabled", "0");  


// Catch l'erreur si l'instanciation la classe SoapServer
// échoue, on retourne l'erreur
try { 
  $server = new SoapServer('operation.wsdl');
  // On ajoute la méthode "getResult" que le serveur va gérer
  $server->addFunction("getResult"); 
} catch (Exception $e) {
  echo 'erreur'.$e;
}

// Si l'appel provient d'une requête POST (Web Service)
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  // On lance le serveur SOAP
  $server->handle();
}
else {
  echo '<strong>This SOAP server can handle following functions : </strong>';
  echo '<ul>';
  foreach($server->getFunctions() as $func) {
    echo '<li>' , $func , '</li>';
  }
  echo '</ul>';
}
?>

wsdl

<?xml version ='1.0' encoding ='UTF-8' ?> 
<definitions name='getResult' 
  targetNamespace='http://example.org/getResult' 
  xmlns:tns='http://example.org/getResult' 
  xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' 
  xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
  xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' 
  xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' 
  xmlns='http://schemas.xmlsoap.org/wsdl/'> 

    <message name='getResultRequest'> 
      <part name='operation' type='xsd:string'/>
      <part name='integer1' type='xsd:int'/>
      <part name='integer2' type='xsd:int'/>
    </message> 
    <message name='getResultResponse'> 
      <part name='result' type='xsd:string'/> 
    </message> 

    <portType name='getResultPortType'> 
      <operation name='getResult'> 
        <input message='tns:getResultRequest'/> 
        <output message='tns:getResultResponse'/> 
      </operation> 
    </portType> 

    <binding name='getResultBinding' type='tns:getResultPortType'> 
      <soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/> 
      <operation name='getResult'> 
        <soap:operation soapAction='urn:xmethods-delayed-quotes#getResult'/> 
        <input> 
          <soap:body use='encoded' namespace='urn:xmethods-delayed-calcul' 
            encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
        </input> 
        <output> 
          <soap:body use='encoded' namespace='urn:xmethods-delayed-calcul' 
            encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
        </output> 
      </operation> 
    </binding> 

    <service name='getResult'> 
      <port name='getResultPort' binding='getResultBinding'> 
        <soap:address location='http://............../soap-server-2.php'/> 
      </port> 
    </service> 
</definitions>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ogg dd trandata 报错
    • ¥15 高缺失率数据如何选择填充方式
    • ¥50 potsgresql15备份问题
    • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
    • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
    • ¥60 pb数据库修改与连接
    • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
    • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
    • ¥20 神经网络Sequential name=sequential, built=False
    • ¥16 Qphython 用xlrd读取excel报错