WSDL 的问题

发布于 2024-12-01 08:42:11 字数 4498 浏览 1 评论 0原文

我正在尝试基于 WSDL 创建一个 PHP Soap 服务器,我被要求根据我们的目的进行修改。我认为问题是以 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>

一般来说,我对这个 Web 服务还很陌生,而且我对此感到很不舒服。任何提示或帮助将不胜感激。谢谢!

I'm trying to create a PHP soap server based on a WSDL I was given to modify for our purposes. The problem is coming in the form of the WSDL file, I think. When I bring it up to test it here: http://www.validwsdl.com/, the response dies out and tells me that the function isn't present.

The idea is that the expected input is 4 items, those 4 items will be put into the function, used, and 4 other items will be returned. I cut out everything but the return in my sample here, but the idea should still work.

This is my PHP code:

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

}

And this is my wsdl file:

<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>

I'm quite new to this web services in general, and I'm having a heck of a time with this. Any tips or help would be greatly appreciated. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眉黛浅 2024-12-08 08:42:11

正如@ghostJago 指出的,您应该使用“文档”样式而不是“rpc”(“文档/文字”是首选样式)。

但也要注意你的命名空间(我看到你使用 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(其中将包含详细信息,以防出现问题)。

祝你好运!

As @ghostJago noted, you should use use "document" style not "rpc" ("document/literal" is the preffered style).

But also watch your namespaces (I see you use urn:InventoryStatus and http://www.elennox.net/server1.php. Which one is it?).

I think something like this is what your are looking for:

<?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>

This will produce the following request/response:

<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>

Also, it is good etiquette :D to declare faults to your operations (which will contain details in case something goes wrong).

Good luck!

擦肩而过的背影 2024-12-08 08:42:11

尝试将两个样式属性更改为相同的值,这样

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

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

哪种 WSDL 样式应该我使用

它非常技术性,所以希望将两个样式引用设置为相同的值应该可以解决您的问题。过去我只真正使用过document/literalrpc/encoded

try changing both the style attributes to the same value, so

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

You can use either document or rpc for the style. This link describes the various different methods for style and use combinations:

Which style of WSDL should I use

Its pretty technical though so hopefully setting both the style references to the same value should sort your issue. In the past I've only really used document/literal or rpc/encoded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文