非WSDL Soap请求“错误请求”

The Problem

i'm trying to integrate with an API from a provider that has not given me a WSDL--i'm assuming that i'll have to make Non-WSDL requests. however, every request i'm making is giving me a "Bad Request" result. i've never worked with a SOAP API before so i'm kind of lost on what i'm doing wrong here.

i've attempted to use the __soapCall(); function to call the API's endpoint and have constructed parameters using an object to try to format it the way the API documentation is requesting.

when the request is generated and dumped using getLastRequest(), i'm noticing that my function call is wrapping everything in a "param0" struct, which does not match what the API's endpoint expects.

so i'm asking two things essentially: 1. what is causing the Bad Request result or is there a way to diagnose it? 2. is this extra struct my parameters are being wrapped in the result of the error? how do i avoid that?

Code:

here's my constructor with options. from what i understand, if i have no wsdl, i should pass "null" (i've created a class that extends SoapClient to add some helper functions that will construct it, hence why i'm using parent::__construct)

$opts = array(
    "location" => $url,
    "uri" => "https://trakpak.co.uk/API/",
    "trace" => true
);

parent::__construct( null, $opts );

here's my call to the actual SOAP function:

$this->base_function = "CreateShipment";
$this->parameters = new \stdClass;
$this->parameters->ApiKey = "fff";

$result = $this->__soapCall( $this->base_function, [ $this->base_function => $this->parameters ] );

this returns:

SOAP Error Code: HTTP: Bad Request

if i dump my last request, this is what i recieve:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="https://trakpak.co.uk/API/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <SOAP-ENV:Body>
      <ns1:CreateShipment>
         <param0 xsi:type="SOAP-ENC:Struct">
            <ApiKey xsi:type="xsd:string">FFF</ApiKey>
         </param0>
      </ns1:CreateShipment>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

i'm unsure if this is how it's supposed to look, as i've never actually worked with SOAP before.

the API is requesting something like this:

<CreateShipment>
   <ApiKey>FFF</ApiKey>
</CreateShipment>

it seems like my request may never actually be reaching the SOAP endpoint, because dumping the response is completely blank. my request itself also seems to have that extra wrapping param0 struct in the CreateShipment tag when the API is not expecting that.

UPDATE

i've managed to work out my "param0" issue, and now my request looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="https://trakpak.co.uk/API/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <SOAP-ENV:Body>
      <ns1:CreateShipment>
         <ApiKey xsi:type="xsd:string">FFF</ApiKey>
      </ns1:CreateShipment>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

which is formatted exactly how they're requesting it, but i'm still getting

SOAP Error Code: HTTP: Bad Request

and no response from the server.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐