2017-08-29 53 views
0

我尝试在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; 
+0

我刚刚删除“ConvertirSoap12”宣言。现在我的错误是“功能客户端:: __构造(),太少的参数0,传递和确切3预计” – Babe59

回答

0

的埃罗r是在这里你的脚本

$service=new SoapClient("http://localhost/webservice/Client.wsdl"); 

$service= new Client("http://localhost/webservice/Client.wsdl", "", ""); 

当你要创建你必须使用你在哪里使用了错误的类名类名称的类的实例替换该行那不存在。另一件事,如果有一个方法需要参数,那么你必须给所有参数的值,或者你可以定义参数默认值作为它的定义。在你的__construct()方法中,你定义了三个参数,但是当你创建一个实例时,你只给出了一个不完美的值。而不是你可以使用__construct($id = '', $nom = '', $prenom = ''),所以只要你不把其他的价值,如果将完美的工作。

+0

我不同意你的答案。 我的但在测试脚本中是调用serviceWeb而不是“客户端”类 – Babe59

相关问题