PHP SoapClient Request

I am trying to send a SOAP request to a newsletter using this WSDL .

Here is my php:

$client = new SoapClient($wsdl_url, array(
    'login' => 'myusername',
    'password' => 'mypassword',
    'trace' => true
));

$client->AddSubscriber(
    new SoapParam('MyFirstName', 'FirstName'),
    new SoapParam('MyLastName', 'LastName'),
    new SoapParam('myemail@someaddress.com', 'Email')
);

I get an exception:

End element 'Body' from namespace 'schemas.xmlsoap.org/soap/envelope/' expected. Found element 'LastName' from namespace ''. Line 2, position 156.

Here's the expected service for AddSubscriber:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <AuthHeader xmlns="admin.ekeryx.com">
      <Username>string</Username>
      <Password>string</Password>
      <AccountID>string</AccountID>
    </AuthHeader>
  </soap:Header>
  <soap:Body>
    <AddSubscriber xmlns="admin.ekeryx.com">
      <subscriber>
        <ID>string</ID>
        <FirstName>string</FirstName>
        <LastName>string</LastName>
        <Email>string</Email>
      </subscriber>
      <overwritable>boolean</overwritable>
    </AddSubscriber>
  </soap:Body>
</soap:Envelope>

Here, what is sent:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="tempuri.org/">
    <SOAP-ENV:Body>
        <ns1:AddSubscriber/>
            <LastName>MyLastName</LastName>
            <Email>myemail@someaddress.com</Email>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I am not very familiar with SOAP and I have been looking for documentation everywhere, but I cannot find a very good link to what I am doing.

Any guidance would be greatly appreciated!


Thanks. Could you give me an example? I am looking at an example on a PHP site that shows:

<?php
class SOAPStruct {
    function SOAPStruct($s, $i, $f) 
    {
        $this->varString = $s;
        $this->varInt = $i;
        $this->varFloat = $f;
    }
}
$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
                                     'uri'      => "http://test-uri/"));
$struct = new SOAPStruct('arg', 34, 325.325);
$soapstruct = new SoapVar($struct, SOAP_ENC_OBJECT, "SOAPStruct", "http://soapinterop.org/xsd");
$client->echoStruct(new SoapParam($soapstruct, "inputStruct"));
?>

You say that I need to create a PHP subscriber class, assign all vars $this->FirstName = $first_name, etc ... and then put it in SoapVar with encoding SOAP_ENC_OBJECT? How can I better represent the subscriber structure?

+3
2

Params

<soap:Body>
<AddSubscriber xmlns="admin.ekeryx.com">
  <subscriber>
    <ID>string</ID>
    <FirstName>string</FirstName>
    <LastName>string</LastName>
    <Email>string</Email>
  </subscriber>
  <overwritable>boolean</overwritable>
</AddSubscriber>

, , SoapVar subrciber.

http://www.php.net/manual/en/soapvar.soapvar.php

- , , XSD : Body, ...

$subscriber = new StdClass();
$subscriber->ID = 'myid';
$subscriber->FirstName = 'First';
$subscriber->LastName = 'Last';

$subscriber = new SoapParam(new SoapVar($subscriber, SOAP_ENC_OBJECT, $type, $xsd), 'subscriber');

$type XSD/WSDL defeinition api, $xsd - URI XSD.

, , Ive PHP- EBay ( haha), 2 , .

+3

, . , , HTTP, SOAP

$client = new SoapClient($wsdl_url, array(
    'login' => 'myusername',
    'password' => 'mypassword',
    'trace' => true
));

, ,

$headerbody = array('Token' => $someToken, 
                    'Version' => $someVersion, 
                    'MerchantID'=>$someMerchantId, 
                      'UserCredentials'=>array('UserID'=>$UserID, 
                                             'Password'=>$Pwd)); 
0

Source: https://habr.com/ru/post/1723782/


All Articles