我尝试在PHP中创建Web服务(并在C#应用程序中使用它)。 我写了很多帖子,但我找不到我的错误。wsdl php:未定义的属性:stdClass
当我测试这个代码,我Client
类的属性不明 (error => Notice: Undefined property: stdClass::$Nom in C:\wamp\www\webservice\index.php on line 8
)
你能帮助我吗?
这里Client.wsdl
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://localhost/webservice/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://localhost/webservice/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://localhost/webservice/">
<s:element name="GetClient">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="id" type="s:int" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetClientResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetClientResult" type="tns:Client" />
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="Client">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="Id" type="s:int" />
<s:element minOccurs="0" maxOccurs="1" name="Nom" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="Prenom" type="s:string" />
</s:sequence>
</s:complexType>
</s:schema>
</wsdl:types>
<wsdl:message name="GetClientSoapIn">
<wsdl:part name="parameters" element="tns:GetClient" />
</wsdl:message>
<wsdl:message name="GetClientSoapOut">
<wsdl:part name="parameters" element="tns:GetClientResponse" />
</wsdl:message>
<wsdl:portType name="ConvertirSoap">
<wsdl:operation name="GetClient">
<wsdl:input message="tns:GetClientSoapIn" />
<wsdl:output message="tns:GetClientSoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ConvertirSoap" type="tns:ConvertirSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetClient">
<soap:operation soapAction="http://localhost/webservice/GetClient" 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="ConvertirSoap12" type="tns:ConvertirSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetClient">
<soap12:operation soapAction="http://localhost/webservice/GetClient" 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="Convertir">
<wsdl:port name="ConvertirSoap" binding="tns:ConvertirSoap">
<soap:address location="http://localhost/webservice/client.php" />
</wsdl:port>
<wsdl:port name="ConvertirSoap12" binding="tns:ConvertirSoap12">
<soap12:address location="http://localhost/webservice/client.php" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
这里Client.php
<?php
class Client {
public $Id;
public $Nom;
public $Prenom;
function __construct($id, $nom, $prenom)
{
$this->Id = $id;
$this->Nom = $nom;
$this->Prenom = $prenom;
}
function GetClient($id)
{
$c = new Client($id, 'Jean', 'DUPONT');
return $c;
}
}
ini_set('soap.wsdl_cache_enabled', 0);
$serversoap=new SoapServer("http://localhost/webservice/Client.wsdl");
$serversoap->setClass("Client");
$serversoap->handle();
?>
这里我的脚本测试
<?php
ini_set('soap.wsdl_cache_enabled', 0);
$service=new SoapClient("http://localhost/webservice/Client.wsdl");
$result = $service->GetClient(5);
echo $result->Nom." ".$result->Prenom;
我刚刚删除“ConvertirSoap12”宣言。现在我的错误是“功能客户端:: __构造(),太少的参数0,传递和确切3预计” – Babe59