Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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通过SOAP请求传递XML和模式作为参数?_Php_Xml_Soap_Xsd_Wsdl - Fatal编程技术网

如何使用PHP通过SOAP请求传递XML和模式作为参数?

如何使用PHP通过SOAP请求传递XML和模式作为参数?,php,xml,soap,xsd,wsdl,Php,Xml,Soap,Xsd,Wsdl,我需要能够通过SOAP API“添加报价”,这需要XML和模式作为请求中的参数传递 对于其他请求,我使用PHP的SoapClient,但我不确定如何格式化此请求?为了测试,我尝试在PHP中通过Curl发送请求,它可以工作,但我想知道如何使用SoapClient。。。有人能帮我吗?非常感谢 下面是SOAP1.1请求和响应示例。显示的占位符需要替换为实际值(即长度、字符串、模式、xml…) 请求: POST /abc/Quote.asmx HTTP/1.1 Host: myserver Conten

我需要能够通过SOAP API“添加报价”,这需要XML和模式作为请求中的参数传递

对于其他请求,我使用PHP的SoapClient,但我不确定如何格式化此请求?为了测试,我尝试在PHP中通过Curl发送请求,它可以工作,但我想知道如何使用SoapClient。。。有人能帮我吗?非常感谢

下面是SOAP1.1请求和响应示例。显示的占位符需要替换为实际值(即长度、字符串、模式、xml…)

请求:

POST /abc/Quote.asmx HTTP/1.1
Host: myserver
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://example.com/AddQuote"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <AddQuote xmlns="http://example.com">
      <connectId>string</connectId>
      <dsQuote>
        <xsd:schema>schema</xsd:schema>xml</dsQuote>
    </AddQuote>
  </soap:Body>
</soap:Envelope>
POST/abc/Quote.asmx HTTP/1.1
主机:myserver
内容类型:text/xml;字符集=utf-8
内容长度:长度
SOAPAction:“http://example.com/AddQuote"
一串
schemaxml
答复:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
 <soap:Body>
   <AddQuoteResponse xmlns="http://example.com">
     <AddQuoteResult>string</AddQuoteResult>
     <dtMessage>xmlxml</dtMessage>
   </AddQuoteResponse>
 </soap:Body>
HTTP/1.1200正常
内容类型:text/xml;字符集=utf-8
内容长度:长度
一串
xml

以下是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://example.com" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://example.com">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://example.com">
<s:element name="AddQuote">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="connectId" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="dsQuote">
<s:complexType>
<s:sequence>
<s:element ref="s:schema"/>
<s:any/>
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="AddQuoteResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="AddQuoteResult" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="dtMessage">
<s:complexType>
<s:sequence>
<s:any minOccurs="0" maxOccurs="unbounded" namespace="http://www.w3.org/2001/XMLSchema" processContents="lax"/>
<s:any minOccurs="1" namespace="urn:schemas-microsoft-com:xml-diffgram-v1" processContents="lax"/>
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="AddQuoteSoapIn">
<wsdl:part name="parameters" element="tns:AddQuote"/>
</wsdl:message>
<wsdl:message name="AddQuoteSoapOut">
<wsdl:part name="parameters" element="tns:AddQuoteResponse"/>
</wsdl:message>
<wsdl:portType name="QuoteSoap">
<wsdl:operation name="AddQuote">
<wsdl:input message="tns:AddQuoteSoapIn"/>
<wsdl:output message="tns:AddQuoteSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="QuoteSoap" type="tns:QuoteSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="AddQuote">
<soap:operation soapAction="http://example.com/AddQuote" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="QuoteSoap12" type="tns:QuoteSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="AddQuote">
<soap12:operation soapAction="http://example.com/AddQuote" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Quote">
<wsdl:port name="QuoteSoap" binding="tns:QuoteSoap">
<soap:address location="http://myserver/abc/Quote.asmx"/>
</wsdl:port>
<wsdl:port name="QuoteSoap12" binding="tns:QuoteSoap12">
<soap12:address location="http://myserver/abc/Quote.asmx"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

这是它应该是什么样子的示例(从执行相同功能的另一个应用程序复制):


71a0-0e82-4c14-5bcb58bf9701-wer4
123456
提交
555555
123456
999
澳元
1.
mrsmith@example.com
mrsmith@example.com
这里有一些评论
123456
1.
3898
大棕色盒子
每个
1.
9.99
9.99

您尝试过什么?soap客户端将使用WSDL,然后从soap请求对象调用函数。不太清楚您为什么认为需要发送模式,您通常只需要具有正确名称空间的XML负载。你能解释一下吗?还是说肥皂剧?向我们展示到目前为止您拥有的代码以及您遇到的问题或错误。我认为需要提供架构的原因是因为我遇到了错误:“致命错误:未捕获的SoapFault异常:[客户端]SOAP-error:编码:对象没有“架构”属性”我将所有数据加载到数组中,我不确定如何将其作为XML传递给参数。感谢您的帮助:)这里有一个例子:我可以使用Curl让它工作,但想知道如何使用soapclient构建它您尝试了什么?soap客户端将使用WSDL,然后从soap请求对象调用函数。不太清楚您为什么认为需要发送模式,您通常只需要具有正确名称空间的XML负载。你能解释一下吗?还是说肥皂剧?向我们展示到目前为止您拥有的代码以及您遇到的问题或错误。我认为需要提供架构的原因是因为我遇到了错误:“致命错误:未捕获的SoapFault异常:[客户端]SOAP-error:编码:对象没有“架构”属性”我将所有数据加载到数组中,我不确定如何将其作为XML传递给参数。感谢您的帮助:)这里有一个例子:我可以使用Curl让它工作,但想知道如何使用SoapClient来构造它
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:mar="http://example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <soap:Header/>
  <soap:Body>
    <mar:AddQuote>
      <mar:connectId>71a0-0e82-4c14-5bcb58bf9701-wer4</mar:connectId>
      <mar:dsQuote>
        <xs:schema id="CustomerQuote" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
          <xs:element name="CustomerQuote" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
            <xs:complexType>
              <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element name="CustomerQuote">
                  <xs:complexType>
                    <xs:sequence>
                      <xs:element name="QuoteID" type="xs:string" minOccurs="0"/>
                      <xs:element name="QuoteStatus" type="xs:string" minOccurs="0"/>
                      <xs:element name="CustomerID" type="xs:string" minOccurs="0"/>
                      <xs:element name="Reference" type="xs:string" minOccurs="0"/>
                      <xs:element name="SalesEntity" type="xs:string" minOccurs="0"/>
                      <xs:element name="WarehouseEntity" type="xs:string" minOccurs="0"/>
                      <xs:element name="EnterDate" type="xs:string" minOccurs="0"/>
                      <xs:element name="EnterTime" type="xs:string" minOccurs="0"/>
                      <xs:element name="ShipDate" type="xs:string" minOccurs="0"/>
                      <xs:element name="ExpiryDate" type="xs:string" minOccurs="0"/>
                      <xs:element name="Terms" type="xs:string" minOccurs="0"/>
                      <xs:element name="ExtendedEx" type="xs:string" minOccurs="0"/>
                      <xs:element name="TaxTotal" type="xs:string" minOccurs="0"/>
                      <xs:element name="ExtendedInc" type="xs:string" minOccurs="0"/>
                      <xs:element name="Currency" type="xs:string" minOccurs="0"/>
                      <xs:element name="SalesRep" type="xs:string" minOccurs="0"/>
                      <xs:element name="TaxNumber" type="xs:string" minOccurs="0"/>
                      <xs:element name="TaxClass" type="xs:string" minOccurs="0"/>
                      <xs:element name="ExchangeRate" type="xs:string" minOccurs="0"/>
                      <xs:element name="QuoteTransactionType" type="xs:string" minOccurs="0"/>
                      <xs:element name="Category1" type="xs:string" minOccurs="0"/>
                      <xs:element name="Category2" type="xs:string" minOccurs="0"/>
                      <xs:element name="Category3" type="xs:string" minOccurs="0"/>
                      <xs:element name="Category4" type="xs:string" minOccurs="0"/>
                      <xs:element name="Category5" type="xs:string" minOccurs="0"/>
                      <xs:element name="Category6" type="xs:string" minOccurs="0"/>
                      <xs:element name="Special1" type="xs:string" minOccurs="0"/>
                      <xs:element name="Special2" type="xs:string" minOccurs="0"/>
                      <xs:element name="NumLines" type="xs:string" minOccurs="0"/>
                      <xs:element name="Completed" type="xs:string" minOccurs="0"/>
                      <xs:element name="SiteCode" type="xs:string" minOccurs="0"/>
                      <xs:element name="Name" type="xs:string" minOccurs="0"/>
                      <xs:element name="Address1" type="xs:string" minOccurs="0"/>
                      <xs:element name="Address2" type="xs:string" minOccurs="0"/>
                      <xs:element name="City" type="xs:string" minOccurs="0"/>
                      <xs:element name="State" type="xs:string" minOccurs="0"/>
                      <xs:element name="PostalCode" type="xs:string" minOccurs="0"/>
                      <xs:element name="Country" type="xs:string" minOccurs="0"/>
                      <xs:element name="DeliveryName" type="xs:string" minOccurs="0"/>
                      <xs:element name="DeliveryAddress1" type="xs:string" minOccurs="0"/>
                      <xs:element name="DeliveryAddress2" type="xs:string" minOccurs="0"/>
                      <xs:element name="DeliveryCity" type="xs:string" minOccurs="0"/>
                      <xs:element name="DeliveryState" type="xs:string" minOccurs="0"/>
                      <xs:element name="DeliveryPostalCode" type="xs:string" minOccurs="0"/>
                      <xs:element name="DeliveryCountry" type="xs:string" minOccurs="0"/>
                      <xs:element name="FreightType" type="xs:string" minOccurs="0"/>
                      <xs:element name="FreightAccount" type="xs:string" minOccurs="0"/>
                      <xs:element name="Carrier" type="xs:string" minOccurs="0"/>
                      <xs:element name="Shipping" type="xs:string" minOccurs="0"/>
                      <xs:element name="Contact" type="xs:string" minOccurs="0"/>
                      <xs:element name="Email" type="xs:string" minOccurs="0"/>
                      <xs:element name="Phone" type="xs:string" minOccurs="0"/>
                      <xs:element name="Fax" type="xs:string" minOccurs="0"/>
                      <xs:element name="Territory" type="xs:string" minOccurs="0"/>
                      <xs:element name="Comment" type="xs:string" minOccurs="0"/>
                      <xs:element name="PriceCategory" type="xs:string" minOccurs="0"/>
                      <xs:element name="IsOpen" type="xs:string" minOccurs="0"/>
                      <xs:element name="Expired" type="xs:string" minOccurs="0"/>
                      <xs:element name="Accepted" type="xs:string" minOccurs="0"/>
                    </xs:sequence>
                  </xs:complexType>
                </xs:element>
                <xs:element name="CustomerQuoteLine">
                  <xs:complexType>
                    <xs:sequence>
                      <xs:element name="QuoteID" type="xs:string" minOccurs="0"/>
                      <xs:element name="LineNumber" type="xs:string" minOccurs="0"/>
                      <xs:element name="LineNumberReference" type="xs:string" minOccurs="0"/>
                      <xs:element name="LineType" type="xs:string" minOccurs="0"/>
                      <xs:element name="ProductID" type="xs:string" minOccurs="0"/>
                      <xs:element name="Barcode" type="xs:string" minOccurs="0"/>
                      <xs:element name="ProductCode" type="xs:string" minOccurs="0"/>
                      <xs:element name="ProductGroup" type="xs:string" minOccurs="0"/>
                      <xs:element name="Description" type="xs:string" minOccurs="0"/>
                      <xs:element name="UnitCode" type="xs:string" minOccurs="0"/>
                      <xs:element name="CustomerProductCode" type="xs:string" minOccurs="0"/>
                      <xs:element name="Quantity" type="xs:string" minOccurs="0"/>
                      <xs:element name="QuantityReserve" type="xs:string" minOccurs="0"/>
                      <xs:element name="QuantityKit" type="xs:string" minOccurs="0"/>
                      <xs:element name="BasePrice" type="xs:string" minOccurs="0"/>
                      <xs:element name="Price" type="xs:string" minOccurs="0"/>
                      <xs:element name="PriceCurr" type="xs:string" minOccurs="0"/>
                      <xs:element name="Discount" type="xs:string" minOccurs="0"/>
                      <xs:element name="UnitPrice" type="xs:string" minOccurs="0"/>
                      <xs:element name="FixedPrice" type="xs:string" minOccurs="0"/>
                      <xs:element name="SpecialPrice" type="xs:string" minOccurs="0"/>
                      <xs:element name="TaxIncluded" type="xs:string" minOccurs="0"/>
                      <xs:element name="PricePer" type="xs:string" minOccurs="0"/>
                      <xs:element name="Override" type="xs:string" minOccurs="0"/>
                      <xs:element name="ExtendedEx" type="xs:string" minOccurs="0"/>
                      <xs:element name="TaxTotal" type="xs:string" minOccurs="0"/>
                      <xs:element name="ExtendedInc" type="xs:string" minOccurs="0"/>
                      <xs:element name="Comment" type="xs:string" minOccurs="0"/>
                      <xs:element name="ShipDate" type="xs:string" minOccurs="0"/>
                      <xs:element name="ExpiryDate" type="xs:string" minOccurs="0"/>
                    </xs:sequence>
                  </xs:complexType>
                </xs:element>
              </xs:choice>
            </xs:complexType>
          </xs:element>
        </xs:schema>
        <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
          <CustomerQuote>
            <CustomerQuote diffgr:id="CustomerQuote1" msdata:rowOrder="0">
              <QuoteID>123456</QuoteID>
              <QuoteStatus>SUBMITTED</QuoteStatus>
              <CustomerID>555555</CustomerID>
              <Reference>123456</Reference>
              <SalesEntity>999</SalesEntity>
              <Currency>AUD</Currency>
              <NumLines>1</NumLines>
              <Contact>mrsmith@example.com</Contact>
              <Email>mrsmith@example.com</Email>
              <Phone/>
              <Comment>Some comment here</Comment>
            </CustomerQuote>
            <CustomerQuoteLine diffgr:id="CustomerQuoteLine1" msdata:rowOrder="0">
              <QuoteID>123456</QuoteID>
              <LineNumber>1</LineNumber>
              <ProductID>3898</ProductID>
              <Description>BIG BROWN BOX</Description>
              <UnitCode>EA</UnitCode>
              <Quantity>1</Quantity>
              <Price>9.99</Price>
              <PriceCurr>9.99</PriceCurr>
            </CustomerQuoteLine>
          </CustomerQuote>
        </diffgr:diffgram>
      </mar:dsQuote>
    </mar:AddQuote>
  </soap:Body>
</soap:Envelope>