2017-08-29 4 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

unknowですが、あなたは私を助けることができますか?

ここ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"déclarationを削除しました。今私のエラーは "Client :: __ construct()を機能させるには引数が少なすぎ、0が渡され、正確に3が期待されます" – Babe59

答えて

0

ERRO rは、あなたが間違ったクラス名を使用しているクラス名を使用する必要が任意のクラスのインスタンスを作成しようとしているとき

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

で、この行を置き換えるスクリプトにここに

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

です存在しない。引数を取るメソッドがある場合は、すべての引数の値を指定するか、引数のデフォルト値をその定義として定義する必要があります。 __construct()メソッドでは3つの引数を定義しますが、インスタンスを作成するときには完全ではない1つの値しか与えませんでした。むしろ__construct($id = '', $nom = '', $prenom = '')を使うことができるので、他の値を入れないときはいつでも完璧に動作します。

+0

私はあなたの答えに同意しません。 私のテストスクリプトでは、 "client"クラスではなくserviceWebを呼び出すことです – Babe59

関連する問題