PHP无法将数据发送到SOAP服务器

时间:2017-04-11 07:38:17

标签: php soap

我的客户端为我提供了SOAP用途的URL,因此我可以将数据直接发送到他们的服务器。当我打开URL时,它给了我这个XML:

<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://tempuri.org/" 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://tempuri.org/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="RegisterApplication">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="oEnt" type="tns:DataCustomer"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="DataCustomer">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="PartnerID" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="Datetime" type="s:dateTime"/>
<s:element minOccurs="0" maxOccurs="1" name="CustomerName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="EmailCustomer" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="CustomerAddress" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="CustomerNumber1" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="CustomerNumber2" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="SubmissionID" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="ListingID" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="SellerName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="SellerNumber" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="EmailSeller" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="SellerAddress" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Product" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="VehicleType" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Year" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="Funding" type="s:decimal"/>
<s:element minOccurs="0" maxOccurs="1" name="LinkIklan" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="ZipCode" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="City" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Kelurahan" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Kecamatan" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="CustDateOfBirth" type="s:dateTime"/>
<s:element minOccurs="1" maxOccurs="1" name="MonthlyIncome" type="s:decimal"/>
<s:element minOccurs="0" maxOccurs="1" name="Brand" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="Tenor" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="Installment" type="s:decimal"/>
<s:element minOccurs="0" maxOccurs="1" name="ImageIDCustomer" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="ImageStnkNoticePajak" type="s:string"/>
</s:sequence>
</s:complexType>
<s:element name="RegisterApplicationResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="RegisterApplicationResult" type="tns:DataCustomerRespond"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="DataCustomerRespond">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Status" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Notes" type="s:string"/>
</s:sequence>
</s:complexType>
</s:schema>
</wsdl:types>
<wsdl:message name="RegisterApplicationSoapIn">
<wsdl:part name="parameters" element="tns:RegisterApplication"/>
</wsdl:message>
<wsdl:message name="RegisterApplicationSoapOut">
<wsdl:part name="parameters" element="tns:RegisterApplicationResponse"/>
</wsdl:message>
<wsdl:portType name="APISoap">
<wsdl:operation name="RegisterApplication">
<wsdl:input message="tns:RegisterApplicationSoapIn"/>
<wsdl:output message="tns:RegisterApplicationSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="APISoap" type="tns:APISoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="RegisterApplication">
<soap:operation soapAction="http://tempuri.org/RegisterApplication" 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="APISoap12" type="tns:APISoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="RegisterApplication">
<soap12:operation soapAction="http://tempuri.org/RegisterApplication" 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="API">
<wsdl:port name="APISoap" binding="tns:APISoap">
<soap:address location="http://example.com/apidigital/api.asmx"/>
</wsdl:port>
<wsdl:port name="APISoap12" binding="tns:APISoap12">
<soap12:address location="http://example.com/apidigital/api.asmx"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

这是我的PHP代码:

<?
$client = new SoapClient("http://example.com/api.asmx?wsdl");
$params = array ( "PartnerID" => "17000000",
                  "Datetime" => "2017-04-11T00:24:59",
                  "CustomerName" => "Robson",
                  "EmailCustomer" => "robson@email.com",
                  "CustomerAddress" => "Somewhere On Earth",
                  "CustomerNumber1" => "08100000000",
                  "CustomerNumber2" => "08380000000",
                  "SubmissionID" => "KOM000000",
                  "ListingID" => "FB120374",
                  "SellerName" => "",
                  "SellerNumber" => "",
                  "EmailSeller" => "",
                  "SellerAddress" => "",
                  "Product" => "Motor",
                  "VehicleType" => "Honda",
                  "Year" => "1995",
                  "Funding" => "2000000",
                  "LinkIklan" => "www.example.com/21938",
                  "ZipCode" => "15322",
                  "City" => "Serpong",
                  "Kelurahan" => "Cisauk",
                  "Kecamatan" => "Sampora",
                  "CustDateOfBirth" => "1971-02-16",
                  "MonthlyIncome" => "9000000",
                  "Brand" => "Honda",
                  "Tenor" => "12",
                  "Installment" => "318500",
                  "ImageIDCustomer" => "https://example.com",
                  "ImageStnkNoticePajak" => "https://example.com" );

$response = $client->RegisterApplication($params);
print_r($response);
?>

我的php总是无法使用SOAP将数据提交到服务器。它总是给我这个错误:

stdClass Object
(
    [RegisterApplicationResult] => stdClass Object
        (
            [Status] => 99
            [Notes] => Object reference not set to an instance of an object.
        )

)

我错过了参数吗?为什么PHP无法将数组内部的数据发送到SOAP服务器?

谢谢

1 个答案:

答案 0 :(得分:1)

您与预期的请求不符。

RegisterApplication操作正在等待RegisterApplication元素作为参数,其中包含oEnt属性,类型为DataCustomer。通常情况下,您应该有一个包含第一个键oEnt的数组,该数组将指向包含所有客户数据的当前数组$params

如果你不想浪费时间,你应该考虑使用WSDL到php生成器,例如生成所有必需类的PackageGenerator项目,以便构造请求参数,发送请求然后最终处理响应。

相关问题