2016-01-22 61 views
0

我现在面临一个问题,我无法使用WebService。 这里是我的WebService的结构:如何使用WSDL和PHP请求SOAP 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) 

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

+0

没有人有什么想法? – Creed

回答

0

如果任何人在世界上是问,这里的解决方案:

$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) ;