简体   繁体   English

如何创建SOAP请求-PHP

[英]How to create SOAP request - PHP

My client uses a provider that uses SOAP for their services, and I don't know anything about it. 我的客户使用的提供商将SOAP用于其服务,而我对此一无所知。 I've read through documentation, SoapClient and a lot more. 我已经阅读了文档,SoapClient和更多内容。

How can I get this to work? 我该如何工作?

Sample request 样品要求

POST /itravel/API/WebService/iTravelAPI_3_0.asmx HTTP/1.1
Host: divingtravel.itravelsoftware.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Header>
    <AuthHeader xmlns="http://tempuri.org/">
      <Username>string</Username>
      <Password>string</Password>
    </AuthHeader>
  </soap12:Header>
  <soap12:Body>
    <GetRegions xmlns="http://tempuri.org/">
      <getRegionsParameters>
        <CountryID>int</CountryID>
        <ObjectTypeID>unsignedByte</ObjectTypeID>
        <ObjectTypeGroupID>unsignedByte</ObjectTypeGroupID>
        <CategoryID>int</CategoryID>
        <LanguageID>string</LanguageID>
        <SeasonID>int</SeasonID>
      </getRegionsParameters>
    </GetRegions>
  </soap12:Body>
</soap12:Envelope>

Sample response 样品回复

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

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <GetRegionsResponse xmlns="http://tempuri.org/">
      <GetRegionsResult>
        <Region>
          <CountryID>int</CountryID>
          <RegionID>int</RegionID>
          <RegionName>string</RegionName>
          <RegionNameTranslationList>
            <Translation xsi:nil="true" />
            <Translation xsi:nil="true" />
          </RegionNameTranslationList>
          <Description>string</Description>
          <DescriptionTranslationList>
            <Translation xsi:nil="true" />
            <Translation xsi:nil="true" />
          </DescriptionTranslationList>
          <RegionCode>string</RegionCode>
          <CountryCode>string</CountryCode>
          <PhotoList>
            <Photo xsi:nil="true" />
            <Photo xsi:nil="true" />
          </PhotoList>
          <ShortDescription>string</ShortDescription>
          <ShortDescriptionTranslationList>
            <Translation xsi:nil="true" />
            <Translation xsi:nil="true" />
          </ShortDescriptionTranslationList>
          <Title>string</Title>
          <TitleTranslationList>
            <Translation xsi:nil="true" />
            <Translation xsi:nil="true" />
          </TitleTranslationList>
          <SEODescription>string</SEODescription>
          <SEODescriptionTranslationList>
            <Translation xsi:nil="true" />
            <Translation xsi:nil="true" />
          </SEODescriptionTranslationList>
          <KeyWords>string</KeyWords>
          <KeyWordsTranslationList>
            <Translation xsi:nil="true" />
            <Translation xsi:nil="true" />
          </KeyWordsTranslationList>
        </Region>
      </GetRegionsResult>
    </GetRegionsResponse>
  </soap12:Body>
</soap12:Envelope>

Currently I have been trying to follow this link , but it doesn't write out anything. 目前,我一直在尝试遵循此链接 ,但是它什么也没写。

My current code, trying to follow the link above: 我当前的代码,尝试按照上面的链接:

<?php
$client = new SoapClient("http://divingtravel.itravelsoftware.com/itravel/API/WebService/iTravelAPI_3_0.asmx", array('soap_version' => SOAP_1_2));
$result = $client('GetCategories');

var_dump($result);
?>

Thanks in advance! 提前致谢!

EDIT: Updated link and provided current code. 编辑:更新了链接并提供了当前代码。

You need to create the request as an object. 您需要将请求创建为对象。 You can also do it with an array. 您也可以使用数组。

$getRegionsRequest = new \stdClass();
$getRegionsRequest->getRegionsParameters = new \stdClass();
$getRegionsRequest->getRegionsParameters->CountryID = 123;
$getRegionsRequest->getRegionsParameters->ObjectTypeID= 123;
$getRegionsRequest->getRegionsParameters->ObjectTypeGroupID = 123;
$getRegionsRequest->getRegionsParameters->CategoryID = 123;
$getRegionsRequest->getRegionsParameters->LanguageID = 'something';
$getRegionsRequest->getRegionsParameters->SeasonID = 123;

$client = new SoapClient("http://divingtravel.itravelsoftware.com/itravel/API/WebService/iTravelAPI_3_0.asmx", array('soap_version' => SOAP_1_2));
$getRegionsResponse = $client->GetRegions($getRegionsRequest);

var_dump($getRegionsResponse);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM