2010-05-27 154 views
0

我想要做的是用SOAP和PHP將從表單捕獲的值加載到CRM系統。我一直在閱讀SOAP一段時間,我不明白如何去做,其他人知道嗎?用PHP發送一條SOAP消息

回答

0

爲了做到這一點,從sourceforge下載一個簡單的soap工具包(如'NuSOAP')可能是最簡單的。

然後您可以編寫類似下面的(例如提交的ISBN號碼):

<?php 
// include the SOAP classes 
require_once('nusoap.php'); 
// define parameter array (ISBN number) 
$param = array('isbn'=>'0385503954'); 
// define path to server application 
$serverpath ='http://services.xmethods.net:80/soap/servlet/rpcrouter'; 
//define method namespace 
$namespace="urn:xmethods-BNPriceCheck"; 
// create client object 
$client = new soapclient($serverpath); 
// make the call 
$price = $client->call('getPrice',$param,$namespace); 
// if a fault occurred, output error info 
if (isset($fault)) { 
     print "Error: ". $fault; 
     } 
else if ($price == -1) { 
     print "The book is not in the database."; 
} else { 
     // otherwise output the result 
     print "The price of book number ". $param[isbn] ." is $". $price; 
     } 
// kill object 
unset($client); 
?> 

這段代碼是直接取自,這也是一個很好的資源,查看 http://developer.apple.com/internet/webservices/soapphp.html

希望這可以幫助。

0

你可能找到了一個解決方案,因爲然後 - 但也許以下幫助這個別人瀏覽:

皁server.php:

<?php 

class MySoapServer { 

    public function getMessage() 
    { 
     return "Hello world!"; 
    } 

    public function add ($n1,$n2) 
    { 
     return $n1+n2; 
    } 

} 


    $option = array ('uri' => 'http://example.org/stacky/soap-server'); 
    $server = new SoapServer(null,$option); 
    $server->setClass('MySoapServer'); 
    $server->handle(); 

?> 

和皁client.php

<?php 

    $options = array ('uri' => 'http://example.org/stacky/soap-server', 
     'location' => 'http://localhost/soap-server.php'); 

    $client = new SoapClient(null,$options); 

    echo $client ->getMessage(); 
    echo "<br>"; 
    echo $client ->add(41,1); 

?>