Реализовать SOAP 1.1 в php - PullRequest
       1

Реализовать SOAP 1.1 в php

0 голосов
/ 27 января 2011

Ниже приведен пример запроса и ответа SOAP 1.1

POST /DEMOWebServices2.8/service.asmx HTTP/1.1
Host: api.efxnow.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "https://api.efxnow.com/webservices2.3/DealRequestAtBest"

<?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>
    <Authenticator xmlns="https://api.efxnow.com/webservices2.3">
      <ApplicationName>string</ApplicationName>
      <IPAddress>string</IPAddress>
      <UserID>string</UserID>
      <MachineName>string</MachineName>
    </Authenticator>
  </soap:Header>
  <soap:Body>
    <DealRequestAtBest xmlns="https://api.efxnow.com/webservices2.3">
      <UserID>string</UserID>
      <PWD>string</PWD>
      <Pair>string</Pair>
    </DealRequestAtBest>
  </soap:Body>
</soap:Envelope>

Ответ -

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?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:Body>
    <DealRequestAtBestResponse xmlns="https://api.efxnow.com/webservices2.3">
      <DealRequestAtBestResult>
        <Success>boolean</Success>
        <ErrorDescription>string</ErrorDescription>
        <ErrorNumber>int</ErrorNumber>
        <Confirmation>string</Confirmation>
        <ConfirmationNumber>string</ConfirmationNumber>
        <Rate>double</Rate>
      </DealRequestAtBestResult>
    </DealRequestAtBestResponse>
  </soap:Body>
</soap:Envelope>

Я хочу знать, как сделать запрос и как обработать ответ, если он имелбыть сделано в php.я прочитал это , но я не могу понять, как бы __setSoapHeaders() и __call() были бы реализованы в моем случае.заранее спасибо.

1 Ответ

1 голос
/ 27 января 2011

Есть библиотека SOAP для PHP, но для простого обмена вы можете рассмотреть возможность создания тела XML-запроса в виде строки и отправки его с помощью функции библиотеки curl.Это гораздо более низкоуровневый сетевой API, который, по крайней мере, я нахожу более простым в использовании.Обратите внимание, что PHP нужно скомпилировать --with-curl [= DIR].

<?php
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $uri);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
    if ((bool)$proxy) {
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Pragma:','Cache-Control:'));
      curl_setopt($ch, CURLOPT_PROXY, $proxy);
    }
    // Apply the XML to our curl call
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data); 

    $out = curl_exec($ch);
    curl_close($ch);
?>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...