我有一个Web服务,我在PHP中使用SOAP客户端调用其中一个操作,但我得到的只是["any"]=> string(120) "falseObject reference not set to an instance of an object.
我想知道我的代码是否有任何问题,因为我相信我与网络服务的连接是%100工作。
我正在创建的xml字符串有什么问题吗?
操作是:
<wsdl:operation name="XmlIslet">
<wsdl:input message="tns:XmlIsletSoapIn"/>
<wsdl:output message="tns:XmlIsletSoapOut"/>
</wsdl:operation>
,WSDL中的参数说明如下:
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="XmlIslet">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="xmlIslem">
<s:complexType>
<s:sequence>
<s:any/>
</s:sequence>
</s:complexType>
</s:element>
<s:element minOccurs="0" maxOccurs="1" name="xmlYetki">
<s:complexType>
<s:sequence>
<s:any/>
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="XmlIsletResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="XmlIsletResult">
<s:complexType mixed="true">
<s:sequence>
<s:any/>
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
我的肥皂和PHP代码如下:
<?php
$username = "username";
$password = "password";
$xmlString = "<Firmalar></Firmalar>";
function strtoXmldocument($str)
{
$dom = new DOMDocument();
$str1 = $str;
return $dom->loadXML($str1);
}
function stringToDataset($xmlString, $username, $password)
{
$client = new SoapClient('http://1.1.1.1/WSTEST/Service.asmx?WSDL');
$response = $client->XmlIslet(strtoXmldocument($xmlString)->documentElement,
strtoXmldocument("<Kullanici><Adi>" .$username. "</Adi><Sifre>" .$password. "</Sifre></Kullanici>")->documentElement);
var_dump($response);
}
stringToDataset($xmlString, $username, $password);
?>
SOAP请求如下:
POST /WSTEST/Service.asmx HTTP/1.1
Host: 1.1.1.1
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<XmlIslet xmlns="http://tempuri.org/">
<xmlIslem>xml</xmlIslem>
<xmlYetki>xml</xmlYetki>
</XmlIslet>
</soap12:Body>
</soap12:Envelope>
SOAP响应:
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<XmlIsletResponse xmlns="http://tempuri.org/">
<XmlIsletResult>xml</XmlIsletResult>
</XmlIsletResponse>
</soap12:Body>
</soap12:Envelope>
vardump
输出为:
usernamepasswordobject(stdClass)#2 (1) { ["XmlIsletResult"]=> object(stdClass)#3 (1) { ["any"]=> string(120) "falseObject reference not set to an instance of an object." } }
编辑:
我试图使用htmlentities($client->__getLastRequest())
获取请求xml,这显示了我的请求的空白部分:
========= REQUEST ==========
string(292)
"<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body>
<ns1:XmlIslet>
<ns1:xmlIslem/>
<ns1:xmlYetki/>
</ns1:XmlIslet>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope> "
答案 0 :(得分:0)
您最有可能与.NET服务进行通信。此错误消息基本上是一个未定义的变量&#34;消息。
WSDL文件说,您请求必须包含两个实体:xmlIslem和xmlYetki。但是他们的内部结构没有正确定义,它可以是任何&#34; -thing。但是,这并不意味着删除Web服务并不期望您提供一些数据。您似乎需要传递一些数据,而这些数据并非如此,因此错误。
我会联系网络服务提供商并索取文档或特定请求示例。