Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP中使用本机SoapClient进行SOAP调用?_Php_Xml_Web Services_Soap_Soap Client - Fatal编程技术网

如何在PHP中使用本机SoapClient进行SOAP调用?

如何在PHP中使用本机SoapClient进行SOAP调用?,php,xml,web-services,soap,soap-client,Php,Xml,Web Services,Soap,Soap Client,我想调用web服务,它也在开发中,在WSDL中定义了一个函数PlaceInvoiceFromStream。函数定义一个要传递的参数Invoice。WSDL导入XSD shema中定义的类型 WSDL如下所示: <?xml version="1.0" encoding="utf-8"?> <definitions name ="inService" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:s

我想调用web服务,它也在开发中,在WSDL中定义了一个函数PlaceInvoiceFromStream。函数定义一个要传递的参数Invoice。WSDL导入XSD shema中定义的类型

WSDL如下所示:

<?xml version="1.0" encoding="utf-8"?>
<definitions name ="inService"
    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsdl="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
    xmlns:tns="http://localhost/ebiz/ws/"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    targetNamespace="http://localhost/ebiz/ws/">
    <import namespace="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
        location="http://localhost/ebiz/ws/Invoice.xsd"
    />
    <message name="getPlaceInvoiceInput">
        <part name="body" element="xsdl:Invoice"/>
    </message>
    <message name="getPlaceInvoiceOutput">
        <part name="body" type="xsd:string"/>
    </message>
    <portType name="inServicePortType">
        <operation name="PlaceInvoiceFromStream">
            <input message="tns:getPlaceInvoiceInput"/>
            <output message="tns:getPlaceInvoiceOutput"/>
        </operation>
    </portType>
    <binding name="inServiceBinding" type="tns:inServicePortType">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="PlaceInvoiceFromStream">
            <soap:operation soapAction="PlaceInvoiceFromStream"/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
    </binding>
    <service name="inService">
        <port name="inServicePort" binding="tns:inServiceBinding">
            <soap:address location="http://localhost/ebiz/ws/soapServer.php"/>
        </port>
    </service>
</definitions>
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDataTypes-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:udt="urn:oasis:names:specification:ubl:schema:xsd:UnqualifiedDataTypes-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" targetNamespace="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" elementFormDefault="qualified" attributeFormDefault="unqualified" version="2.1">
<xsd:import namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" schemaLocation="../common/UBL-CommonAggregateComponents-2.1.xsd"/>
<xsd:import namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" schemaLocation="../common/UBL-CommonBasicComponents-2.1.xsd"/>
<xsd:import namespace="urn:oasis:names:specification:ubl:schema:xsd:UnqualifiedDataTypes-2" schemaLocation="../common/UBL-UnqualifiedDataTypes-2.1.xsd"/>
<xsd:import namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" schemaLocation="../common/UBL-CommonExtensionComponents-2.1.xsd"/>
<xsd:import namespace="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDataTypes-2" schemaLocation="../common/UBL-QualifiedDataTypes-2.1.xsd"/>
<xsd:element name="Invoice" type="InvoiceType"/>
<xsd:complexType name="InvoiceType">
    <xsd:sequence>
        <xsd:element ref="ext:UBLExtensions"/>
        <xsd:element ref="cbc:UBLVersionID"/>
        <xsd:element ref="cbc:CustomizationID" minOccurs="0"/>
        <xsd:element ref="cbc:ProfileID" minOccurs="0"/>
        <xsd:element ref="cbc:ID"></xsd:element>
        <xsd:element ref="cbc:CopyIndicator" minOccurs="0"/>
        <xsd:element ref="cbc:IssueDate"/>
        <xsd:element ref="cbc:InvoiceTypeCode" minOccurs="0"/>
        <xsd:element ref="cbc:Note" minOccurs="0"/>
        <xsd:element ref="cbc:TaxPointDate" minOccurs="0"/>
        <xsd:element ref="cbc:DocumentCurrencyCode" minOccurs="0"/>
        <xsd:element ref="cbc:AccountingCost" minOccurs="0"/>
        <xsd:element ref="cbc:LineCountNumeric" minOccurs="0"/>
        <xsd:element ref="cac:InvoicePeriod" minOccurs="0"/>
        <xsd:element ref="cac:OrderReference" minOccurs="0"/>
        <xsd:element ref="cac:DespatchDocumentReference" minOccurs="0"/>
        <xsd:element ref="cac:ReceiptDocumentReference" minOccurs="0"/>
        <xsd:element ref="cac:ContractDocumentReference" minOccurs="0"/>
        <xsd:element ref="cac:AdditionalDocumentReference" minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element ref="cac:Signature" minOccurs="0"/>
        <xsd:element ref="cac:AccountingSupplierParty"/>
        <xsd:element ref="cac:AccountingCustomerParty"/>
        <xsd:element ref="cac:BuyerCustomerParty" minOccurs="0"/>
        <xsd:element ref="cac:SellerSupplierParty" minOccurs="0"/>
        <xsd:element ref="cac:TaxRepresentativeParty" minOccurs="0"/>
        <xsd:element ref="cac:Delivery" minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element ref="cac:DeliveryTerms" minOccurs="0"/>
        <xsd:element ref="cac:PaymentMeans" maxOccurs="unbounded"/>
        <xsd:element ref="cac:PaymentTerms" minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element ref="cac:PrepaidPayment" minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element ref="cac:AllowanceCharge" minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element ref="cac:TaxTotal" maxOccurs="unbounded"/>
        <xsd:element ref="cac:LegalMonetaryTotal"/>
        <xsd:element ref="cac:InvoiceLine" maxOccurs="unbounded"/>
    </xsd:sequence>
</xsd:complexType>
<?xml version="1.0" encoding="UTF-8"?>
<Invoice
 xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
 xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
 xmlns:sac="urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2"
 xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 http://localhost/ebiz/ws/Invoice.xsd"
 xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
 xmlns:sig="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2">
    <ext:UBLExtensions>
        <ext:UBLExtension>
            <cbc:ID>INVOICE1</cbc:ID>
            <cbc:Name>InvoiceIssuePlaceData</cbc:Name>
            <ext:ExtensionAgencyURI>urn:invoice:issueplace</ext:ExtensionAgencyURI>
            <ext:ExtensionContent>
                <ext:InvoiceIssuePlace>MyCity</ext:InvoiceIssuePlace>
            </ext:ExtensionContent>
        </ext:UBLExtension>
    </ext:UBLExtensions>
    <cbc:UBLVersionID>2.1</cbc:UBLVersionID>
    <cbc:ID>01 1206-2406-568</cbc:ID>`
但是没有成功

XSL转换更改包括:

  • 节点属性成为节点元素
  • 复杂节点值变为“\u1”元素
xml2array更改包括:

  • 属性成为单独的数组
因此,发送到web服务函数的$xmlarr的格式如下:

array(2) {
  ["Invoice"]=>
  array(15) {
    ["ext:UBLExtensions"]=>
    array(1) {
      ["ext:UBLExtension"]=>
      array(4) {
        ["cbc:ID"]=>
        string(10) "INVOICE1"
        ["cbc:Name"]=>
        string(21) "InvoiceIssuePlaceData"
        ["ext:ExtensionAgencyURI"]=>
        string(25) "urn:invoice:issueplace"
        ["ext:ExtensionContent"]=>
        array(1) {
          ["ext:InvoiceIssuePlace"]=>
          string(7) "MyCity"
        }
      }
    }
    ["cbc:UBLVersionID"]=>
    string(3) "2.1"
    ["cbc:ID"]=>
    string(16) "01 1206-2406-568"
...

  ["Invoice_attr"]=>
  array(8) {
    ["xmlns"]=>
    string(54) "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
    ["xmlns:xsi"]=>
    string(41) "http://www.w3.org/2001/XMLSchema-instance"
    ["xmlns:cac"]=>
    string(72) "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
    ["xmlns:cbc"]=>
    string(68) "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
    ["xmlns:sac"]=>
    string(75) "urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2"
    ["xmlns:ext"]=>
    string(72) "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
    ["xmlns:sig"]=>
    string(72) "urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2"
    ["xsi:schemaLocation"]=>
    string(93) "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 http://localhost/ebiz/ws/Invoice.xsd"
  }
}
web服务调用的结果是:

SOAP-ERROR: Encoding: object has no 'UBLExtensions' property
正确的SOAP请求的表单应该是什么?SOAP请求需要什么形式的数组?基于WSDL和XSD,SOAP是否理解“904;”元素?或单独数组中的属性

提前感谢您为解决此问题提供的任何帮助

更新: 已更改的wsdl:

<message name="getPlaceInvoiceInput">
    <part name="Invoice" element="xsdl:InvoiceType"/>

这不是我想要的。我需要密钥中的名称空间。为了使SoapClient能够接受请求数组中键内的名称空间,应该更改/添加哪些内容,例如“ext:UBLExtensions”?

我认为您需要在
UBLExtensions
级别启动
数组,而不是
Invoice
级别。它将您的顶级元素视为发票,它期望在其中找到发票,但未找到发票时会发出投诉:

SOAP-ERROR: Encoding: object has no 'UBLExtensions' property

它不需要第二个
Invoice\u attr
数组,数组元素的名称根据架构中的元素名称,而不是
ref
值。看看
ref
在您的模式中指向了什么(您似乎没有列出它),即
元素应该有一个
名称

您可以添加WSDL和模式吗?这可能比一个示例XML message.WSDL和schema更有用,为您的答案添加了…Tnx。是的,关于阵列在UBLEX级别的启动,您是对的。我也改变了。我现在没有收到任何错误消息,但SoapClient希望数组中包含不带名称空间的键,而我的xml文件中包含带名称空间的键。为了使SoapClient能够接受请求数组中键内的名称空间,应该更改/添加哪些内容,例如“ext:UBLExtensions”?我认为SoapClient将在构建请求时添加名称空间。您将从XML开始,这是不寻常的。SoapClient允许您从数组开始,并将其序列化为SOAP请求。检查请求是否已发送(通过WireShark或
\uu getLastRequest
),您应该会看到名称空间。
$xmlarr = array(
    "UBLExtensions"=>
    array(
      "UBLExtension"=>
      array(
        "ID"=>"INVOICE1",
        "Name"=>"InvoiceIssuePlaceData",
        "ExtensionAgencyURI"=>"urn:invoice:issueplace",
        "ExtensionContent"=>
        array(
          "InvoiceIssuePlace"=>"MyCity"
        )
      )
    ),
    "UBLVersionID"=>"2.1",
    "ID"=>"01 1206-2406-568",
    ...
SOAP-ERROR: Encoding: object has no 'UBLExtensions' property