肥皂错误,编码:对象没有'RecordId'属性

时间:2011-09-01 10:51:14

标签: php soap

我正在网上做一个连接到肥皂网服务的注册表,应该能够通过它保存付款信息。 PHP就像这样

    function create_member_fee()
      {
        $wsdl = 'WSDL LOCATION';
        $client = new mySoap($wsdl, array('trace' => 1));
        $request = array(
           'obj'=>array(
                  'Member'=>array('Number'=>$NUMBER),
                  'Amount'=>$PRICE,
                  'CreditCard'=>array(
                                'TComboBox_ARCreditCardType'=>$_POST['CT'],
                                'CardNumber'=>$_POST['CN'],
                                'ExpDate'=>mktime(0,0,0,$_POST['CM'],1,$_POST['CY']),
                                'SSNumber'=>$NUMBER_PAYER
                                )
             ),
           'opt'=>array('MemberAction'=>new SoapParam('_ActionInsert','ns1:TActionMethod'))
          );
        $result = $client->__call('CreateMemberFee',$request);
        return $result;
      }

这是WSDL函数和复杂类型。

<message name="CreateMemberFee85Request">
<part name="obj" type="ns1:TMemberFee"/>
<part name="opt" type="ns1:TMemberFeeOptions"/>
</message>

<xs:complexType name="TMemberFee">
<xs:sequence>
<xs:element name="Member" type="ns1:TMemberV2"/>
<xs:element name="Payer" type="ns1:TPerson"/>
<xs:element name="ItemCode" type="xs:string"/>
<xs:element name="Amount" type="xs:double"/>
<xs:element name="CreditCard" type="ns1:TCreditCard"/>
<xs:element name="Saleperson" type="xs:string"/>
<xs:element name="ContactName" type="xs:string"/>
<xs:element name="DiscountPercent" type="xs:double"/>
<xs:element name="ReductionPayment" type="xs:double"/>
<xs:element name="DiscountValidUntil" type="xs:dateTime"/>
<xs:element name="PaymentTerm" type="xs:string"/>
<xs:element name="PaymentMode" type="xs:string"/>
<xs:element name="Memo" type="xs:string"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="TMemberV2">
<xs:sequence>
<xs:element name="RecordID" type="xs:int"/>
<xs:element name="Number" type="xs:string"/>
<xs:element name="Name" type="xs:string"/>
<xs:element name="SSNumber" type="xs:string"/>
<xs:element name="Address1" type="xs:string"/>
<xs:element name="Address2" type="xs:string"/>
<xs:element name="Address3" type="xs:string"/>
<xs:element name="Address4" type="xs:string"/>
<xs:element name="ZipCode" type="xs:string"/>
<xs:element name="City" type="xs:string"/>
<xs:element name="CountryCode" type="xs:string"/>
<xs:element name="CountryName" type="xs:string"/>
<xs:element name="CountyCode" type="xs:string"/>
<xs:element name="Phone" type="xs:string"/>
<xs:element name="PhoneLocal" type="xs:string"/>
<xs:element name="PhoneMobile" type="xs:string"/>
<xs:element name="PhoneFax" type="xs:string"/>
<xs:element name="Telex" type="xs:string"/>
<xs:element name="Email" type="xs:string"/>
<xs:element name="Password" type="xs:string"/>
<xs:element name="Group" type="xs:string"/>
<xs:element name="Tag" type="xs:string"/>
<xs:element name="SalesPerson" type="xs:string"/>
<xs:element name="Discount" type="xs:double"/>
<xs:element name="ItemReceivers" type="ns1:ArrayOfItemReceiver"/>
<xs:element name="Contacts" type="ns1:ArrayOfContacts"/>
<xs:element name="PaymentType" type="xs:string"/>
<xs:element name="CurrencyCode" type="xs:string"/>
<xs:element name="NoVat" type="xs:boolean"/>
<xs:element name="LedgerCode" type="xs:string"/>
<xs:element name="RecordCreated" type="xs:dateTime"/>
<xs:element name="RecordModified" type="xs:dateTime"/>
<xs:element name="Blocked" type="xs:boolean"/>
<xs:element name="Dead" type="xs:boolean"/>
<xs:element name="Retierd" type="xs:boolean"/>
<xs:element name="Disabled" type="xs:boolean"/>
<xs:element name="Points" type="xs:double"/>
<xs:element name="BankCode" type="xs:string"/>
<xs:element name="BankAccGroup" type="xs:string"/>
<xs:element name="BankAccount" type="xs:string"/>
<xs:element name="MemberSubGroups" type="ns1:ArrayOfMemberSubGroups"/>
<xs:element name="Carrer" type="ns1:ArrayOfMemberCarrer"/>
<xs:element name="Membership" type="ns1:ArrayOfMemberMemberships"/>
<xs:element name="Education" type="ns1:ArrayOfMemberEducations"/>
<xs:element name="Applications" type="ns1:ArrayOfMemberApplication"/>
<xs:element name="Funds" type="ns1:ArrayOfMemberFunds"/>
<xs:element name="CreditCard" type="ns1:TCreditCard"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="TPerson">
<xs:sequence>
<xs:element name="Number" type="xs:string"/>
<xs:element name="Name" type="xs:string"/>
<xs:element name="SSNumber" type="xs:string"/>
<xs:element name="Address1" type="xs:string"/>
<xs:element name="Address2" type="xs:string"/>
<xs:element name="Address3" type="xs:string"/>
<xs:element name="Address4" type="xs:string"/>
<xs:element name="ZipCode" type="xs:string"/>
<xs:element name="City" type="xs:string"/>
<xs:element name="CountryCode" type="xs:string"/>
<xs:element name="CountryName" type="xs:string"/>
<xs:element name="CountyCode" type="xs:string"/>
<xs:element name="Phone" type="xs:string"/>
<xs:element name="PhoneLocal" type="xs:string"/>
<xs:element name="PhoneMobile" type="xs:string"/>
<xs:element name="PhoneFax" type="xs:string"/>
<xs:element name="Email" type="xs:string"/>
<xs:element name="RecordCreated" type="xs:dateTime"/>
<xs:element name="RecordModified" type="xs:dateTime"/>
<xs:element name="Blocked" type="xs:boolean"/>
<xs:element name="Gender" type="ns1:TGender"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="TCreditCard">
<xs:sequence>
<xs:element name="CardType" type="ns2:TComboBox_ARCreditCardType"/>
<xs:element name="CardNumber" type="xs:string"/>
<xs:element name="ExpDate" type="xs:dateTime"/>
<xs:element name="SSNumber" type="xs:string"/>
<xs:element name="Name" type="xs:string"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="TMemberFeeOptions">
<xs:sequence>
<xs:element name="MemberAction" type="ns1:TActionMethod"/>
</xs:sequence>
</xs:complexType>

<xs:simpleType name="TActionMethod">
<xs:restriction base="xs:string">
<xs:enumeration value="_ActionUse"/>
<xs:enumeration value="_ActionInsert"/>
<xs:enumeration value="_ActionEdit"/>
<xs:enumeration value="_ActionInsertEdit"/>
<xs:enumeration value="_ActionInsertMerge"/>
<xs:enumeration value="_ActionUseInsert"/>
</xs:restriction>
</xs:simpleType>

调用create_member_fee()时生成的错误就像这样

Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object has no 'RecordID' property in...

我在PHP方面相对较新,即便在周末之前完成这项大规模的任务,坦率地说,如果有人可以提供帮助并告诉我为什么会产生这个错误我会很高兴。 $ client-&gt; __ getLastRequest()不起作用,所以我不知道请求中的xml是怎样的,这让我的生活变得更加困难。

5 个答案:

答案 0 :(得分:5)

我刚解决了这个问题,这是一个使用对象而不是庞大而混乱的数组的问题。你必须不要忘记完全按照它们在wsdl中出现的方式映射对象。并且您必须在您的实例中为所有这些值分配值,如果emty只使用''。这是我的代码。

    class TMemberV2 
        { 
            public $RecordID;
            public $Number;
            public $Name;
            public $SSNumber;
            public $Address1;
            public $Address2;
            public $Address3;
            public $Address4;
            public $ZipCode;
            public $City;
            public $CountryCode;
            public $CountryName;
            public $CountyCode;
            public $Phone;
            public $PhoneLocal;
            public $PhoneMobile;
            public $PhoneFax;
            public $Telex;
            public $Email;
            public $Password;
            public $Group;
            public $Tag;
            public $SalesPerson;
            public $Discount;
            public $ItemReceivers;
            public $Contacts;
            public $PaymentType;
            public $CurrencyCode;
            public $NoVat;
            public $LedgerCode;
            public $RecordCreated;
            public $RecordModified;
            public $Blocked;
            public $Dead;
            public $Retierd;
            public $Disabled;
            public $Points;
            public $BankCode;
            public $BankAccGroup;
            public $BankAccount;
            public $MemberSubGroups;
            public $Carrer;
            public $Membership;
            public $Education;
            public $Applications;
            public $Funds;
            public $CreditCard;
        } 

        class TCreditCard
        {
            public $CardType;
            public $CardNumber;
            public $ExpDate;
            public $SSNumber;
            public $Name;
        }

        class TMemberFee 
        { 
            public $Member;
            public $Payer;
            public $ItemCode;
            public $Amount;
            public $CreditCard;
            public $Saleperson;
            public $ContactName;
            public $DiscountPercent;
            public $DiscountValidUntil;
            public $PaymentTerm;
            public $PaymentMode;
            public $Memo;
        } 

        $member = new TMemberV2(); 
                $member->RecordID = $id;
                $member->Number = $kennitala;
                $member->Name = $nafn;
                $member->SSNumber = $kennitala;
                $member->Address1 = $heimilisfang;
                $member->Address2 = '';
                $member->Address3 = '';
                $member->Address4 = '';
                $member->ZipCode = $postnumer;
                $member->City = $sveitarfelag;
                $member->CountryCode = 'IS';
                $member->CountryName = 'Ísland';
                $member->CountryCode = 'IS';
                $member->Phone = $simanumer;
                $member->PhoneLocal = '';
                $member->PhoneMobile = $farsimi;
                $member->PhoneFax = '';
                $member->Telex = '';
                $member->Email = $netfang;
                $member->Password = '';
                $member->Group = '';
                $member->Tag = '';
                $member->SalesPerson = '';
                $member->Discount = '$';
                $member->ItemReceivers = '';
                $member->Contacts = '';
                $member->PaymentType = 'test';
                $member->CurrencyCode = '';
                $member->NoVat = '';
                $member->LedgerCode = '';
                $member->RecordCreated = '';
                $member->RecordModified = '';
                $member->Blocked = '';
                $member->Dead = '';
                $member->Retierd = '';
                $member->Disabled = '';
                $member->Points = '';
                $member->BankCode = '';
                $member->BankAccGroup = '';
                $member->BankAccount = '';
                $member->MemberSubGroups = '';
                $member->Carrer = '';
                $member->Membership = '';
                $member->Education = '';
                $member->Applications = '';
                $member->Funds = '';
                $member->CreditCard = '';

$creditCard = new TCreditCard();
        $creditCard->CardType = $_POST['CT'];
        $creditCard->CardNumber = $_POST['CN'];
        $creditCard->ExpDate = mktime(0,0,0,$_POST['CM'],1,$_POST['CY']);
        $creditCard->SSNumber = $kt_forradamanns;

        $memberFee = new TMemberFee();
        $memberFee->Member = $member;
        $memberFee->Payer = '';
        $memberFee->ItemCode = '';
        $memberFee->Amount = $namskeid_verd;
        $memberFee->CreditCard = $creditCard;
        $memberFee->Saleperson = '';
        $memberFee->ContactName = '';
        $memberFee->DiscountPercent = '';
        $memberFee->ReductionPayment = '';
        $memberFee->DiscountValidUntil = strtotime("now");
        $memberFee->PaymentTerm = '';
        $memberFee->PaymentMode = '';
        $memberFee->Memo = '';

$wsdl = 'SOME WSDL';
    $client = new mySoap($wsdl, array('trace' => 1));
    $param = new SoapParam($memberFee, 'ns1:TMemberFee');
    $param1 = new SoapParam('_ActionInsertEdit', 'ns1:TMemberFeeOptions');
        $result = $client->__call('CreateMemberFee',array('obj'=>$param, 'opt'=>$param1));

答案 1 :(得分:4)

无需声明类的最佳方法是使用stdClass。要使其工作,请保留对象和对象属性中字段的名称。

    $TMemberFee = new stdClass();
    $TMemberV2 = new stdClass();
    ...
    $TMemberV2->RecordID = $id_holder_var;

    ...
    $TMemberFee->Member = $TMemberV2;
    ...

这对我有用,我希望它适合你。

答案 2 :(得分:3)

定义他声称为“遗失财产”的所有字段

因此,如果您正在使用数组,并且它说它缺少属性'GetData',请执行:

$ requestArray ['GetData'] ='';

以及每个字段等等,直到它正常工作。

答案 3 :(得分:2)

我曾经被这样的错误所迷惑。事实证明,该请求中的属性并未丢失,而是在响应中。错误消息不包含任何规范。

答案 4 :(得分:1)

另见https://bugs.php.net/bug.php?id=50997 - 看起来你遇到了这个错误 - 即PHP在没有使用对象时似乎有序列问题。