简体   繁体   中英

How to send XML to wsdl endpoint

I hope you all doing well. I need little help with SOAP API. I want to send XML and I have WSDL endpoint. Can someone help me, how to do this? help would be appreciated.

First, what would be a good approach CURL and soapClient?

This is the endpoint http://some_ip/some_channel/services/some_service?wsdl

And the XML is here:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
   <ban:someMthod>
      <chnlNum>somenumber</chnlNum>
      <chnlPasWd>some password</chnlPasWd>
      <userNum>some number</userNum>
      <amount>some amount</amount>
      <requestDate>some date</requestDate>
      <requestId>some random number</requestId>
   </ban:someMethod>
</soapenv:Body>
</soapenv:Envelope>

The whole request will look like this.

$soapurl = "http://some_ip_endpoint";
$date = date("Y-m-d h:i:sa");
$requestID = (new DateTime())->getTimestamp();


// Make your own custom request.

$xml_post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Header/>
        <soapenv:Body>
        <ban:someMthod>
            <chnlNum>somenumber</chnlNum>
            <chnlPasWd>some password</chnlPasWd>
            <userNum>some number</userNum>
            <amount>some amount</amount>
            <requestDate>' . $date . '</requestDate>
            <requestId>' . $requestID . '</requestId>
        </ban:someMethod>
        </soapenv:Body>
        </soapenv:Envelope>';


// Don't for get to mention a proper header 

    $headers = array(
            "Content-Type: text/xml; charset=UTF-8",
            "Pragma: no-cache",
            "Content-length: " . strlen($xml_post_string),
            "Connection: Keep-Alive"
        );


// The actual curl request.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $soapurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);


// Get a response and filter it out accordingly 

$response = curl_exec($ch);
curl_close($ch);
$xml = $response;
$xml = preg_replace("/(<\/?)(\w+):([^>]*>)/", '$1$2$3', $xml);
$xml = simplexml_load_string($xml);
$json = json_encode($xml);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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