Как создать произвольный SOAP-запрос с использованием PHP? - PullRequest
1 голос
/ 16 апреля 2010

У меня проблема с SOAP в PHP. Я пытаюсь создать произвольный запрос SOAP, используя класс Nusoap_client. Полный запрос, включая заголовки, должен выглядеть следующим образом. Конечно, заполнители (строки) должны быть заменены фактическими значениями.

POST /services/RecipeCouponAPI11.asmx HTTP/1.1
Host: example.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.example.com/services/GetCouponAll"

<?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="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <RCAuthenticator xmlns="http://www.example.com/services/">
      <UserName>string</UserName>
      <Password>string</Password>
    </RCAuthenticator>
  </soap:Header>
  <soap:Body>
    <GetCouponAll xmlns="http://www.example.com/services/">
      <campaignCode>string</campaignCode>
    </GetCouponAll>
  </soap:Body>
</soap:Envelope>

Я попробовал следующий код PHP без удачи. Похоже, запрос не отформатирован правильно. Любые идеи о том, как заставить его работать?

<?php
$client = new Nusoap_client('http://www.example.com/services/RecipeCouponAPI11.asmx');
$headers = new SoapHeader(
    'http://www.example.com/services/',
    'RCAuthenticator',
    (object)array(
        'UserName' => 'username',
        'Password' => 'password'
    ),
    false
);

$client->setHeaders(array($headers));

$response = $client->call(
    'GetCouponAll',
    array('campaignCode' => 'campaigncode'),
    null,
    'http://www.example.com/services/GetCouponAll'
);
?>

1 Ответ

3 голосов
/ 17 апреля 2010

В конце концов нашел решение.

<?php
$client = new SoapClient('http://www.example.com/services/RecipeCouponAPI11.asmx?wsdl');
$header = new SoapHeader(
    'http://www.example.com/services/',
    'RCAuthenticator',
    array(
        'UserName' => 'username',
        'Password' => 'password'
    )
);

$client->__setSoapHeaders($header);

$response = $client->GetCouponAll(array('campaignCode' => ''));
?>
...