2016-05-30 11 views
-2

SOAPクライアントを使用してSOAPメッセージを送信します。私は、例としてWSDLファイルを持っています。 SOAP UIを使用してWSDLファイルを使用できます。PHPを使用してSOAPメッセージを送信するにはどうすればよいですか?

私の要件は、SOAPメッセージを特定のデバイスまたはどこか他の場所に送信するときに、メッセージごとにメッセージIDを生成する必要があることです。

PHPを使用してSOAPリクエストを書く方法を教えてください。

私は非常にこれに新しいので、すべての例/リンクを高く評価しました。

+0

この[URL]を確認してください(http://stackoverflow.com/help)あなたがインターネット上で何かを見つける必要があり –

+0

をあなたの品質を持ち上げるために有用であろう。このSOAPのものは広く使われています。 –

+1

[PHPからSOAPリクエストを投稿する方法](http://stackoverflow.com/questions/471115/how-to-post-soap-request-from-php) –

答えて

1

このようなものはありますか?

<?php 
    //Data, connection, auth 
    $dataFromTheForm = $_POST['fieldName']; // request data from the form 
    $soapUrl = "https://connecting.website.com/soap.asmx?op=DoSomething"; // asmx URL of WSDL 
    $soapUser = "username"; // username 
    $soapPassword = "password"; // password 

    // xml post structure 

    $xml_post_string = '<?xml version="1.0" encoding="utf-8"?> 
         <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
          <soap:Body> 
          <GetItemPrice xmlns="http://connecting.website.com/WSDL_Service"> // xmlns value to be set to your's WSDL URL 
           <PRICE>'.$dataFromTheForm.'</PRICE> 
          </GetItemPrice > 
          </soap:Body> 
         </soap:Envelope>'; // data from the form, e.g. some ID number 

     $headers = array(
        "Content-type: text/xml;charset=\"utf-8\"", 
        "Accept: text/xml", 
        "Cache-Control: no-cache", 
        "Pragma: no-cache", 
        "SOAPAction: http://connecting.website.com/WSDL_Service/GetPrice", 
        "Content-length: ".strlen($xml_post_string), 
       ); //SOAPAction: your op URL 

     $url = $soapUrl; 

     // PHP cURL for https connection with auth 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
     curl_setopt($ch, CURLOPT_URL, $url); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc 
     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); 

     // converting 
     $response = curl_exec($ch); 
     curl_close($ch); 

     // converting 
     $response1 = str_replace("<soap:Body>","",$response); 
     $response2 = str_replace("</soap:Body>","",$response1); 

     // convertingc to XML 
     $parser = simplexml_load_string($response2); 
     // user $parser to get your data out of XML response and to display it. 
?> 
+0

とほぼ同じです。しかし、ここで私はあなたがユーザー名とパスワードを使用しているのを見ることができます。 しかし、私の要求は、私がURLを通してメッセージを送信し、私がそれを送信しているときに、それに対してIDを取得する必要があるということです。 – Saurya

関連する問題