3

我目前正在尝试提供基于 SOAP RPC/Literal 的 Web 服务。
这是我的 WSDL 文件:

<?xml version="1.0" encoding="iso-8859-1"?>
<!--WSDL genere permettant de decrire le service web.-->
<!--Partie 1 : Definitions-->
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" name="WSDL" targetNamespace="http://soap.mycompany.org/wsdl/" xmlns:typens="http://soap.mycompany.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <!--partie 2 : Types-->
  <types>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://soap.mycompany.org/wsdl/">
      <xsd:complexType name="calculatorAuthInput">
        <xsd:annotation>
          <xsd:documentation>^CSoapHandler-calculatorAuth^</xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
          <xsd:element name="operation" type="xsd:string">
            <xsd:annotation>
              <xsd:documentation>^CSoapHandler-calculatorAuth-operation^</xsd:documentation>
            </xsd:annotation>
          </xsd:element>
          <xsd:element name="entier1" type="xsd:integer">
            <xsd:annotation>
              <xsd:documentation>^CSoapHandler-calculatorAuth-entier1^</xsd:documentation>
            </xsd:annotation>
          </xsd:element>
          <xsd:element name="entier2" type="xsd:integer">
            <xsd:annotation>
              <xsd:documentation>^CSoapHandler-calculatorAuth-entier2^</xsd:documentation>
            </xsd:annotation>
          </xsd:element>
        </xsd:sequence>
      </xsd:complexType>
      <xsd:complexType name="calculatorAuthOutput">
        <xsd:sequence>
          <xsd:element name="result" type="xsd:integer">
            <xsd:annotation>
              <xsd:documentation>^CSoapHandler-calculatorAuth-result^</xsd:documentation>
            </xsd:annotation>
          </xsd:element>
        </xsd:sequence>
      </xsd:complexType>
    </xsd:schema>
  </types>
  <!--partie 3 : Message-->
  <message name="calculatorAuthRequest">
    <part name="parameters" type="typens:calculatorAuthInput"/>
  </message>
  <message name="calculatorAuthResponse">
    <part name="parameters" type="typens:calculatorAuthOutput"/>
  </message>
  <!--partie 4 : Port Type-->
  <portType name="MyPort">
    <!--partie 5 : Operation-->
    <operation name="calculatorAuth">
      <input message="typens:calculatorAuthRequest"/>
      <output message="typens:calculatorAuthResponse"/>
    </operation>
  </portType>
  <!--partie 6 : Binding-->
  <binding name="MyBinding" type="typens:MyPort">
    <soap:binding xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="calculatorAuth">
      <soap:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" soapAction=""/>
      <input name="calculatorAuthRequest">
        <soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
      </input>
      <output name="calculatorAuthResponse">
        <soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
      </output>
    </operation>
  </binding>
  <!--Partie 7 : Service-->
  <service name="MyService">
    <documentation>Documentation du WebService</documentation>
    <!--partie 8 : Port-->
    <port name="MyPort" binding="typens:MyBinding">
      <soap:address xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" location="http://localhost/mywebsite/?login=1&amp;username=myusername&amp;password=mypassword&amp;m=webservices&amp;a=soap_server&amp;class=CSoapHandler&amp;suppressHeaders=1"/>
    </port>
  </service>
</definitions>

我在想一切都是正确的,但似乎不是因为我在启动我的 SOAP 客户端时遇到了这个错误(我对 soapUI 有同样的错误):

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Body>
      <SOAP-ENV:Fault>
         <faultcode>SOAP-ENV:Server</faultcode>
         <faultstring>Procedure 'calculatorAuth' not present</faultstring>
      </SOAP-ENV:Fault>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这是我的 SOAP 客户端示例代码:

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

  $client = new SoapClient("http://localhost/mywebsite/index.php?login=myusername:mypassword=webservices&a=soap_server&class=CSoapHandler&wsdl&wsdl_mode=CWSDLRPCLiteral", array("trace" => true));
  try { 
    echo "<pre>";
    $res = $client->calculatorAuth(array("operation" => "add", "entier1" => 888, "entier2" => 987654321)); 
    print_r($res);
  }
  catch (SoapFault $e) { 
    echo $e;  
  } 
?>

我不明白为什么找不到我的程序。我徒劳地花了几个小时来搜索我的 WSDL 中的问题在哪里。
我还没有真正尝试过这些技术,也许有人可以给我一个外部观点?

4

1 回答 1

0

您的声明中没有<xsd:complexType name="calculatorAuth">任何<types>内容?看来您正在尝试调用不存在的方法。

于 2012-08-14T01:30:16.333 回答