在PHP客户端中读取Microsoft .NET SOAP Web服务生成的数据集的最佳策略是什么?
我有来自网络服务的以下回复
192.168.21.12 gitlab.dev
到目前为止,我的PHP代码非常简单:
<?xml version="1.0" encoding="UTF-8"?>
<DataSet xmlns="http://Example/wsExchangeExample/">
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="Categoria" type="xs:string" minOccurs="0" />
<xs:element name="titolo" type="xs:string" minOccurs="0" />
<xs:element name="Cognome" type="xs:string" minOccurs="0" />
<xs:element name="Nome" type="xs:string" minOccurs="0" />
<xs:element name="Cod_fisc" type="xs:string" minOccurs="0" />
<xs:element name="DIP" type="xs:dateTime" minOccurs="0" />
<xs:element name="DPI" type="xs:dateTime" minOccurs="0" />
<xs:element name="DR" type="xs:dateTime" minOccurs="0" />
<xs:element name="L_PI" type="xs:string" minOccurs="0" />
<xs:element name="N_Iscrizione" type="xs:int" minOccurs="0" />
<xs:element name="d_canc" type="xs:dateTime" minOccurs="0" />
<xs:element name="D_nas" type="xs:dateTime" minOccurs="0" />
<xs:element name="L_nas" type="xs:string" minOccurs="0" />
<xs:element name="P_nascita" type="xs:string" minOccurs="0" />
<xs:element name="Scheda" type="xs:boolean" minOccurs="0" />
<xs:element name="Note" type="xs:string" minOccurs="0" />
<xs:element name="CodIscritto" type="xs:string" minOccurs="0" />
<xs:element name="Sesso" type="xs:string" minOccurs="0" />
<xs:element name="Stato" type="xs:string" minOccurs="0" />
<xs:element name="Senatore" type="xs:boolean" minOccurs="0" />
<xs:element name="Ultrasettantenne" type="xs:boolean" minOccurs="0" />
<xs:element name="Giovane" type="xs:boolean" minOccurs="0" />
<xs:element name="Pensionato" type="xs:boolean" minOccurs="0" />
<xs:element name="Dipendente" type="xs:boolean" minOccurs="0" />
<xs:element name="Carica" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<NewDataSet xmlns="">
<Table diffgr:id="Table1" msdata:rowOrder="0">
<Categoria>B</Categoria>
<titolo>Ing. Junior</titolo>
<Cognome>BLACK</Cognome>
<Nome>PETER</Nome>
<Cod_fisc>AAAAAAAAAA</Cod_fisc>
<DIP>2002-12-03T00:00:00+01:00</DIP>
<DPI>2002-12-03T00:00:00+01:00</DPI>
<L_PI>MILANO</L_PI>
<N_Iscrizione>1</N_Iscrizione>
<D_nas>1971-03-08T00:00:00+01:00</D_nas>
<L_nas>Borgo Sesia</L_nas>
<P_nascita>MI</P_nascita>
<Scheda>false</Scheda>
<CodIscritto>1B</CodIscritto>
<Sesso>1</Sesso>
<Stato>Attivo</Stato>
<Senatore>false</Senatore>
<Ultrasettantenne>false</Ultrasettantenne>
<Giovane>false</Giovane>
<Pensionato>false</Pensionato>
<Dipendente>true</Dipendente>
</Table>
<Table diffgr:id="Table2" msdata:rowOrder="1">
<Categoria>B</Categoria>
<titolo>Ing. Junior</titolo>
<Cognome>WHITE</Cognome>
<Nome>CAROL</Nome>
<Cod_fisc>XXXXXXXXX</Cod_fisc>
<DIP>2003-01-14T00:00:00+01:00</DIP>
<DPI>2003-01-14T00:00:00+01:00</DPI>
<L_PI>Como</L_PI>
<N_Iscrizione>9999</N_Iscrizione>
<D_nas>1975-03-09T00:00:00+01:00</D_nas>
<L_nas>Como</L_nas>
<Scheda>false</Scheda>
<CodIscritto>2B</CodIscritto>
<Sesso>2</Sesso>
<Stato>Attivo</Stato>
<Senatore>false</Senatore>
<Ultrasettantenne>false</Ultrasettantenne>
<Giovane>false</Giovane>
<Pensionato>false</Pensionato>
<Dipendente>false</Dipendente>
</Table>
</NewDataSet>
</diffgr:diffgram>
</DataSet>
它返回类似:
/* Initialize webservice with your WSDL */
$client = new SoapClient("http://www.myurl.com/wsExchangeExample/wservice.asmx?WSDL");
/* Invoke webservice method with your parameters, in this case: Function1 */
$response = $client->__soapCall("Function1", array());
/* Print webservice response */
var_dump($response);
如何解析此响应?我尝试过以下方法:
object(stdClass)[2]
public 'Function1Result' =>
object(stdClass)[3]
public 'schema' => string '<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet"><xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element name="Table"><xs:complexType><xs:sequence><xs:element name="Categoria" type="xs:string" minOccurs="0"/><xs:element name="titolo" type="xs:string" minOccurs="0"/><xs:element name="Cognome" type="xs:string" minOccurs="0"/>'... (length=1916)
public 'any' => string '<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"><NewDataSet xmlns=""><Table diffgr:id etc. etc.
但是我收到错误($ response不是字符串)。 那么,这是在PHP中执行此任务的最佳方法?
答案 0 :(得分:1)
您有stdClass
个实例,请阅读更多here。您可以使用RitornaTabellaConfineResult
阅读$response->RitornaTabellaConfineResult
。但是,您可能希望将其转换为array
。一种方法是json_decode和json_encode:
$responseArray = json_decode(json_encode($response), true);
//Test
echo var_dump($responseArray);