dqwh1205 2018-02-26 14:48
浏览 37

如何创建SOAP请求 - PHP

My client uses a provider that uses SOAP for their services, and I don't know anything about it. I've read through documentation, SoapClient and a lot more.

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.

  • 写回答

1条回答 默认 最新

  • dtlc84438 2018-02-26 15:00
    关注

    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);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 BV260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)