使用 Guzzle SOAP 请求但一直接收未设置为对象实例的对象引用
Using Guzzle SOAP request but kept receiving Object reference not set to an instance of an object
这是我的 guzzle 代码在 soap 上请求的函数 API。我一直收到错误 "Object reference not set to an instance of an object." 但响应是 200。我需要生成 QuotationNo.
我需要post这些数据到外部API数据库
当数据成功post到数据库时,将创建 QuotationNo
public function getQuotation()
{
$factory = new Factory();
$client = $factory->create(new Client(), 'http://something.com/GetQuotation/GetQuotation.asmx?WSDL',
[
'stream' => true,
'stream_context' => [
'ssl' => [
'allow_self_signed' => true
],
'socket' => [
'bindto' => 'serveripaddress'
]
]
]
);
$data = [
'param' => [
'TokenId' => '1pBt8l93-aTX1-E7J6-A6Qx-cWb3Abc84Eg6',
'AgentCode' => '30144-36-C',
'AgentID' => 'hqrebate',
'SumInsured' => 98005,
'BasicPrem' => 23006,
'ClassCode' => '2-01',
'SubClassCode' => '01',
'CarRegistrationNo' => 'PGS3881',
'InsuredName' => 'Testing Insured',
'InsuredIC' => '830711075133',
'InsuredEmail' => 'testing@hotmail.com',
'InsuredContactNo' => '60123450005',
'InsuredAddress1' => '153,',
'InsuredAddress2' => 'Jln Persiaran Meranti,',
'InsuredAddress3' => 'Bandar Seri Damansara',
'InsuredPostcode' => '55220'
]
];
$result = $client->call('GenerateQuotation', $data);
var_dump($result);
exit;
}
这是wsdl格式
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="GenerateQuotation">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="param" type="tns:QuotationReq"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="QuotationReq">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="TokenId" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="AgentCode" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="AgentID" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="SumInsured" type="s:double"/>
<s:element minOccurs="1" maxOccurs="1" name="BasicPrem" type="s:double"/>
<s:element minOccurs="0" maxOccurs="1" name="ClassCode" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="SubClassCode" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="CarRegistrationNo" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="InsuredName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="InsuredIC" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="InsuredEmail" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="InsuredContactNo" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="InsuredAddress1" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="InsuredAddress2" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="InsuredAddress3" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="InsuredPostcode" type="s:string"/>
</s:sequence>
</s:complexType>
<s:element name="GenerateQuotationResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GenerateQuotationResult" type="tns:QuotationResp"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="QuotationResp">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="QuotationNo" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="ErrorDesc" type="s:string"/>
</s:sequence>
</s:complexType>
</s:schema>
</wsdl:types>
对于那些能帮助我的人,我非常感谢你,因为我遇到这个问题已经有一段时间了。
我只是修改这个:
$result = $client->call('GenerateQuotation', $data);
对此:
$result = $client->call('GenerateQuotation', [$data]);
任务完成。
这是我的 guzzle 代码在 soap 上请求的函数 API。我一直收到错误 "Object reference not set to an instance of an object." 但响应是 200。我需要生成 QuotationNo.
我需要post这些数据到外部API数据库
当数据成功post到数据库时,将创建 QuotationNo
public function getQuotation()
{
$factory = new Factory();
$client = $factory->create(new Client(), 'http://something.com/GetQuotation/GetQuotation.asmx?WSDL',
[
'stream' => true,
'stream_context' => [
'ssl' => [
'allow_self_signed' => true
],
'socket' => [
'bindto' => 'serveripaddress'
]
]
]
);
$data = [
'param' => [
'TokenId' => '1pBt8l93-aTX1-E7J6-A6Qx-cWb3Abc84Eg6',
'AgentCode' => '30144-36-C',
'AgentID' => 'hqrebate',
'SumInsured' => 98005,
'BasicPrem' => 23006,
'ClassCode' => '2-01',
'SubClassCode' => '01',
'CarRegistrationNo' => 'PGS3881',
'InsuredName' => 'Testing Insured',
'InsuredIC' => '830711075133',
'InsuredEmail' => 'testing@hotmail.com',
'InsuredContactNo' => '60123450005',
'InsuredAddress1' => '153,',
'InsuredAddress2' => 'Jln Persiaran Meranti,',
'InsuredAddress3' => 'Bandar Seri Damansara',
'InsuredPostcode' => '55220'
]
];
$result = $client->call('GenerateQuotation', $data);
var_dump($result);
exit;
}
这是wsdl格式
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="GenerateQuotation">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="param" type="tns:QuotationReq"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="QuotationReq">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="TokenId" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="AgentCode" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="AgentID" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="SumInsured" type="s:double"/>
<s:element minOccurs="1" maxOccurs="1" name="BasicPrem" type="s:double"/>
<s:element minOccurs="0" maxOccurs="1" name="ClassCode" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="SubClassCode" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="CarRegistrationNo" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="InsuredName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="InsuredIC" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="InsuredEmail" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="InsuredContactNo" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="InsuredAddress1" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="InsuredAddress2" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="InsuredAddress3" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="InsuredPostcode" type="s:string"/>
</s:sequence>
</s:complexType>
<s:element name="GenerateQuotationResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GenerateQuotationResult" type="tns:QuotationResp"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="QuotationResp">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="QuotationNo" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="ErrorDesc" type="s:string"/>
</s:sequence>
</s:complexType>
</s:schema>
</wsdl:types>
对于那些能帮助我的人,我非常感谢你,因为我遇到这个问题已经有一段时间了。
我只是修改这个: $result = $client->call('GenerateQuotation', $data);
对此: $result = $client->call('GenerateQuotation', [$data]);
任务完成。