PHP 5 SOAP'ı merhaba dünya uygulama hata ayıklama yardıma mı ihtiyacınız var

1 Cevap php

Ben web üzerinde var her öğretici okuduktan sonra çalışmak için PHP 5 SOAP uzantısı almaya çalışıyorum, ama boşuna oldum. Bu çok sinir bozucu oldu ve ben yanlış gidiyor ve neden nerede olduğumu kimse işaret olabilir eğer gerçekten takdir ediyorum.

Lütfen şimdiden yardım ve daha fazla ayrıntı için teşekkürler ben mecbur edeceğiz gerekiyordu.

Aşağıdaki gibi olduğu WSDL:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions name="test"
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:s1="http://microsoft.com/wsdl/types/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
targetNamespace="http://tempuri.org/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:import namespace="http://microsoft.com/wsdl/types/" />

<s:element name="getUser">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="username" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="getUserResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="getUserResult" type="tns:bookUser" />
</s:sequence>
</s:complexType>

</s:element>

<s:complexType name="bookUser">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="ID" type="s:int" />
<s:element minOccurs="1" maxOccurs="1" name="GUID" type="s1:guid" />
<s:element minOccurs="0" maxOccurs="1" name="login" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="pass" type="s:string" />
</s:sequence>
</s:complexType>

</s:schema>
</wsdl:types>

<wsdl:message name="getUserSoapIn">
<wsdl:part name="parameters" element="tns:getUser" />
</wsdl:message>
<wsdl:message name="getUserSoapOut">
<wsdl:part name="parameters" element="tns:getUserResponse" />
</wsdl:message>


<wsdl:portType name="test">
<wsdl:operation name="getUser">
<wsdl:input message="tns:getUserSoapIn" />
<wsdl:output message="tns:getUserSoapOut" />
</wsdl:operation>
</wsdl:portType>

<wsdl:binding name="testBinding" type="tns:test">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getUser">
<soap:operation soapAction="http://tempuri.org/getUser" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>

<wsdl:service name="testService">
<wsdl:port name="testPort" binding="tns:testBinding">
<soap:address location="http://127.0.0.1/index.php" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

Sunucu için kod:

<?php

function getUser($param) {

return array(
'bookUser'=>array
(
'ID'=>1,
'GUID'=>2,
'login'=>$param->username,
'pass'=>$param->password
)
);
}

ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("http://127.0.0.1/1.wsdl");
$server->addFunction("getUser");

$server->handle();

?>

ve istemci için kod:

$client = new SoapClient("http://127.0.0.1/index.php?wsdl", array('exceptions' => 0));

try {
$arr_data = array
(
array
(
'username'=>'xyz',
'password'=>'abc'
)
);
print_r($client->__soapCall("getUser",$arr_data));
}
catch (SoapFault $result) {
print_r($result);
} 

1 Cevap

WSDL aşağıdaki satırı değiştirmeyi deneyin:

<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">

Sizin dev sunucunun gerçek hostname / ip adresi. Örneğin Sizin dev sunucu 192.168.0.100 de yerel ağdaki olsaydı:

<s:schema elementFormDefault="qualified" targetNamespace="http://192.168.0.100/">

Benim dev sunucu üzerinde yukarıdaki kodunuzu kullandım ve WSDL o sabit hat kadar bir hataya neden oldu.