WSDL问题

时间:2011-08-22 19:06:13

标签: php soap wsdl

我正在尝试基于我为了我们的目的而修改的WSDL创建一个PHP肥皂服务器。我认为问题是以WSDL文件的形式出现的。当我把它带到这里进行测试时:http://www.validwsdl.com/,响应消失并告诉我该功能不存在。

这个想法是预期的输入是4个项目,这4个项目将被放入函数,使用,并将返回4个其他项目。我在这里删除了我的样本中的所有内容,但这个想法应该仍然可行。

这是我的PHP代码:

ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
 $server = new SoapServer("InventoryInquiry.wsdl");
 $server->addFunction("GetInventoryStatus");
 $server->handle(); 


function GetInventoryStatus($request) {
$dealerBranch = 1;//default branch to 1
$inStock = 0;//default in stock to 0
$cantTrack = 0; //used to check if branch is tracked
$estDeliveryTime = "";
$estDeliveryDate = "";
$deliveryLocation = "";


  return array(
          'InStock' => $inStock,
          'EstDeliveryDate' =>$estDeliveryDate,
          'EstDeliveryTime'=> $estDeliveryTime,
          'DeliveryLocation' => $dealerBranch
          );

}

这是我的wsdl文件:

<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://www.elennox.net/server1.php/" 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://www.elennox.net/server1.php" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">  
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://www.elennox.net/server1.php">
      <s:element name="GetInventoryStatus">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="DealerCode" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="SupplierCode" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="PartNumber" type="s:string" />
            <s:element minOccurs="1" maxOccurs="1" name="Quantity" type="s:int" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="GetInventoryStatusResponse">       
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="InStock" type="s:int" />
            <s:element minOccurs="0" maxOccurs="1" name="EstDeliveryDate" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="EstDeliveryTime" type="s:string" />
            <s:element minOccurs="1" maxOccurs="1" name="DeliveryLocation" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
  </s:schema>
</wsdl:types>  
  <wsdl:message name="InventoryRequestRequest">
    <wsdl:part name="parameters" element="tns:GetInventoryStatus" />
  </wsdl:message>
  <wsdl:message name="InventoryRequestResponse">
    <wsdl:part name="parameters" element="tns:GetInventoryStatusResponse" />
  </wsdl:message>  
  <wsdl:portType name="InventoryStatusPortType">
    <wsdl:operation name="InventoryRequest">
      <wsdl:input message="tns:InventoryRequestRequest" />
      <wsdl:output message="tns:InventoryRequestResponse" />
    </wsdl:operation>
  </wsdl:portType>  
  <wsdl:binding name="InventoryStatusBinding" type="tns:InventoryStatusPortType">
    <soap:binding style='rpc' transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="InventoryRequest">
      <soap:operation soapAction="http://www.elennox.net/server1.php#InventoryStatus" style="document" />
      <wsdl:input>
        <soap:body use="literal" namespace="urn:InventoryStatus"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" namespace="urn:InventoryStatus"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>  
  <wsdl:service name="InventoryStatus">
    <wsdl:port name="InventoryStatusPort" binding="tns:InventoryStatusBinding">
      <soap:address location="http://www.elennox.net/server1.php" />
    </wsdl:port>
  </wsdl:service>      
</wsdl:definitions>

我对这个网络服务一般都很陌生,而且我对此有点兴奋。任何提示或帮助将不胜感激。谢谢!

2 个答案:

答案 0 :(得分:2)

正如@ghostJago所说,你应该使用“文档”样式而不是“rpc”(“document / literal”是优先样式​​)。

但也请注意您的命名空间(我看到您使用urn:InventoryStatushttp://www.elennox.net/server1.php。它是哪一个?)。

我认为这样的事情正是你所寻找的:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions 
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:s="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://www.elennox.net/server1.php"
    xmlns:tns="http://www.elennox.net/server1.php" 
    name="InventoryStatusService">

    <wsdl:types>
        <s:schema elementFormDefault="qualified" targetNamespace="http://www.elennox.net/server1.php">
            <s:element name="GetInventoryStatus">
                <s:complexType>
                    <s:sequence>
                        <s:element minOccurs="0" maxOccurs="1" name="DealerCode" type="s:string" />
                        <s:element minOccurs="0" maxOccurs="1" name="SupplierCode" type="s:string" />
                        <s:element minOccurs="0" maxOccurs="1" name="PartNumber" type="s:string" />
                        <s:element minOccurs="1" maxOccurs="1" name="Quantity" type="s:int" />
                    </s:sequence>
                </s:complexType>
            </s:element>
            <s:element name="GetInventoryStatusResponse">
                <s:complexType>
                    <s:sequence>
                        <s:element minOccurs="0" maxOccurs="1" name="InStock" type="s:int" />
                        <s:element minOccurs="0" maxOccurs="1" name="EstDeliveryDate" type="s:string" />
                        <s:element minOccurs="0" maxOccurs="1" name="EstDeliveryTime" type="s:string" />
                        <s:element minOccurs="1" maxOccurs="1" name="DeliveryLocation" type="s:string" />
                    </s:sequence>
                </s:complexType>
            </s:element>
        </s:schema>
    </wsdl:types>
    <wsdl:message name="InventoryRequestRequest">
        <wsdl:part name="parameters" element="tns:GetInventoryStatus" />
    </wsdl:message>
    <wsdl:message name="InventoryRequestResponse">
        <wsdl:part name="parameters" element="tns:GetInventoryStatusResponse" />
    </wsdl:message>
    <wsdl:portType name="InventoryStatusPortType">
        <wsdl:operation name="InventoryRequest">
            <wsdl:input message="tns:InventoryRequestRequest" />
            <wsdl:output message="tns:InventoryRequestResponse" />
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="InventoryStatusBinding" type="tns:InventoryStatusPortType">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="InventoryRequest">
            <soap:operation soapAction="http://www.elennox.net/server1.php#InventoryStatus" style="document" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="InventoryStatus">
        <wsdl:port name="InventoryStatusPort" binding="tns:InventoryStatusBinding">
            <soap:address location="http://www.elennox.net/server1.php" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

这将产生以下请求/响应:

<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:ser="http://www.elennox.net/server1.php">
   <soapenv:Body>
      <ser:GetInventoryStatus>
         <!--Optional:-->
         <ser:DealerCode>...</ser:DealerCode>
         <!--Optional:-->
         <ser:SupplierCode>...</ser:SupplierCode>
         <!--Optional:-->
         <ser:PartNumber>...</ser:PartNumber>
         <ser:Quantity>...</ser:Quantity>
      </ser:GetInventoryStatus>
   </soapenv:Body>
</soapenv:Envelope>

<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:ser="http://www.elennox.net/server1.php">
   <soapenv:Body>
      <ser:GetInventoryStatusResponse>
         <!--Optional:-->
         <ser:InStock>...</ser:InStock>
         <!--Optional:-->
         <ser:EstDeliveryDate>...</ser:EstDeliveryDate>
         <!--Optional:-->
         <ser:EstDeliveryTime>...</ser:EstDeliveryTime>
         <ser:DeliveryLocation>...</ser:DeliveryLocation>
      </ser:GetInventoryStatusResponse>
   </soapenv:Body>
</soapenv:Envelope>

此外,这是一个很好的礼节:D为您的操作声明错误(如果出现问题,将包含详细信息)。

祝你好运!

答案 1 :(得分:1)

尝试将样式属性更改为相同的值,所以

<soap:binding style='document' transport="http://schemas.xmlsoap.org/soap/http" />  

您可以使用文档 rpc 作为样式。此链接描述了样式和使用组合的各种不同方法:

Which style of WSDL should I use

它非常技术性,但希望将样式引用设置为相同的值应该排序您的问题。在过去,我只使用 document / literal rpc / encoded