【问题标题】:How to request SOAP webService using WSDL with PHP如何使用 WSDL 和 PHP 请求 SOAP webService
【发布时间】:2016-01-26 17:49:22
【问题描述】:

我现在面临一个问题,我无法使用 WebService。 这是我的 WebService 的结构:

 array (size=22)
  0 => string 'struct TPAcess {
 TPKRequest KRequest;
}' (length=53)
  1 => string 'struct TPKRequest {
 AOIRequest REQUESTS;
}' (length=56)
  2 => string 'struct AOIRequest {
 TPIRequest REQUEST;
}' (length=57)
  3 => string 'struct TPIRequest {
 string ORDERID;
 string CPID;
}' (length=57)
  4 => string 'struct TPAResponse {
 TPKResponses KEYRESPONSE;
}' (length=63)
  5 => string 'struct TPKResponses {
 AOTPORequest REQUESTS;
 TPTechnicalError TECHNICALERROR;
}' (length=92)
  6 => string 'struct AOTPORequest {
 TPOutputRequest REQUEST;
}' (length=59)
  7 => string 'struct TPOutputRequest {
 string ORDERID;
 string CPID;
 ArrayOfTPSystem SYSTEMS;
 TPRequestError ERROR;
}' (length=107)
  8 => string 'struct ArrayOfTPSystem {
 TPSystem SYSTEM;
}' (length=44)
  9 => string 'struct TPSystem {
 int SYSTEMID;
 string PRODUCTLINE;
 ArrayOfTPOrder ORDERS;
}' (length=79)
  10 => string 'struct ArrayOfTPOrder {
 TPOrder ORDER;
}' (length=41)
  11 => string 'struct TPOrder {
 string TYPEOFORDER;
 string ORDERLABEL;
 string FIRSTSALEORDERLABEL;
 string NOPO;
 string PODATE;
 Applicant APPLICANT;
 ArrayOfCP CPS;
 AOSKey SKEYS;
}' (length=184)
  12 => string 'struct Applicant {
 int APPLICANTID;
 string APPLICANTNAME;
}' (length=61)
  13 => string 'struct ArrayOfCP {
 CPU CPU;
}' (length=31)
  14 => string 'struct CPU {
 string LABEL;
}' (length=29)
  15 => string 'struct AOSKey {
 SubKey SUBKEY;
}' (length=40)
  16 => string 'struct SubKey {
 string SUBKEYTYPE;
 ArrayOfEncryptCode ENCRYPTCODES;
}' (length=71)
  17 => string 'struct ArrayOfEncryptCode {
 EncryptCode ENCRYPTCODE;
}' (length=55)
  18 => string 'struct EncryptCode {
 string LABEL;
 string VALUE;
}' (length=52)
  19 => string 'struct TPRequestError {
}' (length=25)
  20 => string 'struct TPError {
 string CODE;
 string DESCRIPTION;
}' (length=53)
  21 => string 'struct TPTechnicalError {
}' (length=27)

以及我如何尝试从我的 PHP 函数中访问它:

public function consumeWebService(){
    $client = new \Soapclient('http://url_of_the_WebService?WSDL', array(
        'login'=>"myLogin",
        'password'=>"myPassword"
    ));

    $request = $client->TPAccess(array(
        'KREQUEST'=>array(
            'REQUESTS'=>array(
                'REQUEST'=>array(
                    'ORDERID'=>'numberOfMyOrderID'
                    )
                )
            )
        ));
        $result = $client->TPAccess($request);
        var_dump($result);die;
}

但我得到的唯一结果如下:

object(stdClass)[280]
  public 'KRESPONSES' => 
    object(stdClass)[281]
      public 'TECHNICALERROR' => 
        object(stdClass)[282]
          public 'CODE' => string 'ERR_XML_001' (length=11)
          public 'DESCRIPTION' => string 'Core technical error preventing the message to be managed (e.g. invalid input file structure such as missing tag or mandatory value).' (length=133)

你们有什么想法吗?谢谢!

【问题讨论】:

  • 没人知道吗?

标签: php web-services soap wsdl


【解决方案1】:

如果世界上有人问,这就是解决方案:

$soapUrl = "https://url_of_my_webService/Function.asmx?WSDL";
    $client = new \SoapClient($soapUrl,array(
        'login'=>'login',
        'password'=>'password',
        'trace'=>true
    ));

    $orderID = "something";
    $cpid = "other_thing";

    $xml_post_string = '<?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>
                    <TPAccess xmlns="http://tempuri.org/">
                        <KREQUEST>
                            <REQUESTS>
                                <REQUEST>
                                    <ORDERID>'.$orderID.'</ORDERID>
                                    <CPID>'.$cpuid.'</CPUID>
                                </REQUEST>
                            </REQUESTS>
                        </KREQUEST>
                    </TPAccess>
                </soap12:Body>
            </soap12:Envelope>';

    $call = $client->__doRequest($xml_post_string, $soapUrl, "http://namespace.org/Function", 1.1) ;

【讨论】:

    猜你喜欢
    • 2017-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    • 1970-01-01
    相关资源
    最近更新 更多