How can learn/verify if I have a SOAP client installed on my account? I'm looking to possibly use a vb install with joomla, and i'm reading about how it works with a soap client.
Thanks
PT
This is a discussion on SOAP Client in the Shared & Semi-Dedicated forum
How can learn/verify if I have a SOAP client installed on my account? I'm looking to possibly use a vb install with joomla, and i'm ...
How can learn/verify if I have a SOAP client installed on my account? I'm looking to possibly use a vb install with joomla, and i'm reading about how it works with a soap client.
Thanks
PT
Well, SOAP clients are generally code libraries for a specific language. SOAP is, in a very brief nutshell, just a way to share typed-data from server to server (or app to app in this case).
Since it sounds like you're using PHP, a package called nuSOAP is the most common client around. There is also some native support for SOAP in PHP5, but last I checked it was still experimental.
You can grab a copy of nuSOAP at http://sourceforge.net/projects/nusoap/.
--Jason
Neither the SOAP client nor the SOAP server are enabled on 'my' server... if they were, this is what I would see in 'phpinfo()'...
Last edited by Vin DSL; 03-05-2006 at 06:47 AM.
DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.
PHP4 doesn't have a SOAP extension as far as I know. It is only in PHP5, and even then it doesn't appear fully ready for prime time (there's no version info in the PHP manual yet, for instance).
nuSOAP lets you do everything the SOAP extension does, both client- and server-wise and it works great in PHP4.
I guess it all depends upon the implementation... who knows what kind of 'magic' they're using here?
I use a SOAP client, on my site, to pull 'linkto' results from Google Web APIs.
Here's the (PHP) app: http://www.lenon.com/popularity.html
Here's a small snippet of the code...
SOAP (and WSDL) do work here...PHP Code:// load namespace uris into an array of uri => prefix
$namespaces = array(
"http://schemas.xmlsoap.org/soap/envelope/" => "SOAP-ENV",
$XMLSchemaVersion => "xsd",
$XMLSchemaVersion . "-instance" => "xsi",
"http://schemas.xmlsoap.org/soap/encoding/" => "SOAP-ENC",
"http://soapinterop.org/xsd" => "si");
$xmlEntities = array("quot" => '"', "amp" => "&",
"lt" => "<", "gt" => ">", "apos" => "'");
// $path can be a complete endpoint url, with the other parameters left blank:
// $soap_client = new soap_client("http://path/to/soap/server");
class soap_client{
function soap_client($path, $server = false, $port = false){
$this -> port = 80;
$this -> path = $path;
$this -> server = $server;
$this -> errno;
$this -> errstring;
$this -> debug_flag = false;
$this -> debug_str = "";
$this -> username = "";
$this -> password = "";
$this -> action = "";
$this -> incoming_payload = "";
$this -> outgoing_payload = "";
$this -> response = "";
$this -> action = "";
// endpoint mangling
if(ereg("^http://", $path)){
$path = str_replace("http://", "", $path);
$this -> path = strstr($path, "/");
$this -> debug("path = $this->path");
if(ereg(":", $path)){
$this -> server = substr($path, 0, strpos($path, ":"));
$this -> port = substr(strstr($path, ":"), 1);
$this -> port = substr($this -> port, 0, strpos($this -> port, "/"));
}else{
$this -> server = substr($path, 0, strpos($path, "/"));
}
}
if($port){
$this -> port = $port;
}
}
function setCredentials($username, $pword){
$this -> username = $username;
$this -> password = $pword;
}
function send($msg, $action = "", $timeout = 0){
// where msg is an soapmsg
if($this -> debug_flag){
$msg -> debug_flag = true;
}
$this -> action = $action;
return $this -> sendPayloadHTTP10(
$msg,
$this -> server,
$this -> port,
$timeout,
$this -> username,
$this -> password
);
}
function sendPayloadHTTP10($msg, $server, $port, $timeout = 0, $username = "", $password = ""){
if($timeout > 0){
$fp = fsockopen($server, $port, $this -> errno, $this -> errstr, $timeout);
}else{
$fp = fsockopen($server, $port, $this -> errno, $this -> errstr);
}
if (!$fp){
$this -> debug("Couldn't open socket connection to server!");
$this -> debug("Server: $this->server");
return 0;
}
$credentials = "";
if($username != ""){
$credentials = "Authorization: Basic " . base64_encode("$username:$password") . "\r\n";
}
$soap_data = $msg -> serialize();
$this -> outgoing_payload =
"POST " . $this -> path . " HTTP/1.0\r\n" .
"User-Agent: SOAPx4 v0.5\r\n" .
"Host: " . $this -> server . "\r\n" .
$credentials .
"Content-Type: text/xml\r\nContent-Length: " . strlen($soap_data) . "\r\n" .
"SOAPAction: \"$this->action\"" . "\r\n\r\n" .
$soap_data;
// send
if(!fputs($fp, $this -> outgoing_payload, strlen($this -> outgoing_payload))){
$this -> debug("Write error");
}
// get reponse
while($data = fread($fp, 32768)){
$incoming_payload .= $data;
}
fclose($fp);
$this -> incoming_payload = $incoming_payload;
// $response is a soapmsg object
$this -> response = $msg -> parseResponse($incoming_payload);
$this -> debug($msg -> debug_str);
return $this -> response;
}
function debug($string){
if($this -> debug_flag){
$this -> debug_str .= "soap_client: $string\n";
}
}
} // end class soap_client
// soap message class
class soapmsg{
// params is an array of soapval objects
function soapmsg($method, $params, $method_namespace = "http://testuri.org", $new_namespaces = false){
// globalize method namespace
global $methodNamespace;
$methodNamespace = $method_namespace;
// make method struct
$this -> value = new soapval($method, "struct", $params, $method_namespace);
if(is_array($new_namespaces)){
global $namespaces;
$i = count($namespaces);
foreach($new_namespaces as $v){
$namespaces[$v] = "ns" . $i++;
}
$this -> namespaces = $namespaces;
}
$this -> payload = "";
$this -> debug_flag = false;
$this -> debug_str = "entering soapmsg() with soapval " . $this -> value -> name . "\n";
}
function make_envelope($payload){
global $namespaces;
foreach($namespaces as $k => $v){
$ns_string .= "xmlns:$v=\"$k\" ";
}
return "<SOAP-ENV:Envelope $ns_string SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" .
$payload .
"</SOAP-ENV:Envelope>\n";
}
function make_body($payload){
return "<SOAP-ENV:Body>\n" .
$payload .
"</SOAP-ENV:Body>\n";
}
function createPayload(){
$value = $this -> value;
$payload = $this -> make_envelope($this -> make_body($value -> serialize()));
$this -> debug($value -> debug_str);
$payload = "<?xml version="1.0\"?>\n" . $payload;
if($this -> debug_flag){
$payload .= $this -> serializeDebug();
}
$this -> payload = str_replace("\n", "\r\n", $payload);
}
function serialize(){
if($this -> payload == ""){
$this -> createPayload();
return $this -> payload;
}else{
return $this -> payload;
}
}
// returns a soapval object
function parseResponse($data){
$this -> debug("Entering parseResponse()");
// $this->debug(" w/ data $data");
if(ereg("^(.*)\r\n\r\n", $data)){
$this -> debug("found proper separation of headers and document");
$this -> debug("getting rid of headers, stringlen: " . strlen($data));
// CHANGES BELOW
$offset = strpos($data, "\r\n\r\n<");
$clean_data = substr($data, $offset + 2);
$clean_data = ereg_replace("\r\n", "", $clean_data);
// $clean_data = ereg_replace("^.*\r\n\r\n", "", $data);
// $clean_data = ereg_replace("^.*\r\n\r\n<","<", $data);
$this -> debug("cleaned data, stringlen: " . strlen($clean_data));
// $this->debug($clean_data);
}else{
// return fault
return new soapval("fault", "SOAPStruct", array(new soapval("faultcode", "string", "SOAP-MSG"), new soapval("faultstring", "string", "HTTP error"), new soapval("faultdetail", "string", "HTTP headers were not immediately followed by '\r\n\r\n'")));
}
$this -> debug("about to create parser instance w/ data");
// parse response
$response = new soap_parser($clean_data);
// return array of parameters
$ret = $response -> get_response();
$this -> debug($response -> debug_str);
return $ret;
}
// dbg
function debug($string){
if($this -> debug_flag){
$this -> debug_str .= "soapmsg: $string\n";
}
}
// preps debug data for encoding into soapmsg
function serializeDebug(){
if($this -> debug_flag){
return "<!-- DEBUG INFO:\n" . $this -> debug_str . "-->\n";
}else{
return "";
}
}
}
// soap value object
class soapval{
function soapval($name = "", $type = false, $value = -1, $namespace = false, $type_namespace = false){
global $soapTypes, $typemap, $namespaces, $methodNamespace, $XMLSchemaVersion;
// detect type if not passed
if(!$type){
$this -> debug("soapval - DETECT TYPE: '$name' type: '$type' value: $value\n");
if(is_array($value) && count($value) >= 1){
foreach($value as $k => $v){
if(ereg("^[0-9]+$", $k)){
$type = "array";
}else{
$type = "struct";
}
break;
}
}elseif(is_int($value)){
$type = "int";
}elseif(is_float($value) || $value == "NaN" || $value == "INF"){
$type = "float";
}else{
$type = gettype($value);
}
}
// php type name mangle
if($type == "integer"){
$type = "int";
}
$this -> soapTypes = $soapTypes;
$this -> name = $name;
$this -> value = "";
$this -> type = $type;
$this -> type_code = 0;
$this -> type_prefix = false;
$this -> array_type = "";
$this -> debug_flag = true;
$this -> debug_str = "";
$this -> debug("Entering soapval - name: '$name' type: '$type' value: $value");
if($namespace){
$this -> namespace = $namespace;
if(!isset($namespaces[$namespace])){
$namespaces[$namespace] = "ns" . (count($namespaces) + 1);
}
$this -> prefix = $namespaces[$namespace];
}
// get type prefix
if(ereg(":", $type)){
$this -> type = substr(strrchr($type, ":"), 1, strlen(strrchr($type, ":")));
$this -> type_prefix = substr($type, 0, strpos($type, ":"));
}elseif($type_namespace){
if(!isset($namespaces[$type_namespace])){
$namespaces[$type_namespace] = "ns" . (count($namespaces) + 1);
}
$this -> type_prefix = $namespaces[$type_namespace];
// if type namespace was not explicitly passed, and we're not in a method struct:
}elseif(!$this -> type_prefix && !isset($this -> namespace)){
// try to get type prefix from typeMap
if(!$ns = $this -> verify_type($type)){
// else default to method namespace
$this -> type_prefix = $namespaces[$methodNamespace];
}else{
$this -> type_prefix = $namespaces[$ns];
}
}
// if scalar
if(in_array($this -> type, $typemap[$XMLSchemaVersion])){
$this -> type_code = 1;
$this -> addScalar($value, $this -> type, $name);
// if array
}elseif(eregi("^(array|ur-type)$", $this -> type)){
$this -> type_code = 2;
$this -> addArray($value);
// if struct
}elseif(eregi("struct", $this -> type)){
$this -> type_code = 3;
$this -> addStruct($value);
}elseif(is_array($value)){
$this -> type_code = 3;
$this -> addStruct($value);
}else{
$this -> type_code = 1;
$this -> addScalar($value, "string", $name);
}
}
function addScalar($value, $type, $name = ""){
$this -> debug("adding scalar '$name' of type '$type'");
$this -> value = $value;
return true;
}
function addArray($vals){
$this -> debug("adding array '$this->name' with " . count($vals) . " vals");
$this -> value = array();
if(is_array($vals) && count($vals) >= 1){
foreach($vals as $k => $v){
$this -> debug("checking value $k : $v");
// if soapval, add..
if(get_class($v) == "soapval"){
$this -> value[] = $v;
$this -> debug($v -> debug_str);
// else make obj and serialize
}else{
if(is_array($v)){
if(ereg("[a-zA-Z\-]*", key($v))){
$type = "struct";
}else{
$type = "array";
}
}elseif(!ereg("^[0-9]+$", $k) && $this -> verify_type($k)){
$type = $k;
}elseif(is_int($v)){
$type = "int";
}elseif(is_float($v) || $v == "NaN" || $v == "INF"){
$type = "float";
}else{
$type = gettype($v);
}
$new_val = new soapval("item", $type, $v);
$this -> debug($new_val -> debug_str);
$this -> value[] = $new_val;
}
}
}
return true;
}
function addStruct($vals){
$this -> debug("adding struct '$this->name' with " . count($vals) . " vals");
if(is_array($vals) && count($vals) >= 1){
foreach($vals as $k => $v){
// if serialize, if soapval
if(get_class($v) == "soapval"){
$this -> value[] = $v;
$this -> debug($v -> debug_str);
// else make obj and serialize
}else{
if(is_array($v)){
foreach($v as $a => $b){
if($a == "0"){
$type = "array";
}else{
$type = "struct";
}
break;
}
}elseif($this -> verify_type($k)){
$this -> debug("got type '$type' for value '$v' from typemap!");
$type = $k;
}elseif(is_int($v)){
$type = "int";
}elseif(0 && (is_float($v) || $v == "NaN" || $v == "INF")){ // MODIFIED: to work with Google
$type = "float";
}else{
$type = gettype($v);
if($type == "boolean"){ // MODIFIED: to work with Google
switch($v){
case 0:
case false:
case "":
$v = "false";
break;
default:
$v = "true";
break;
}
}
$this -> debug("got type '$type' for value '$v' from php gettype()!");
}
$new_val = new soapval($k, $type, $v);
$this -> debug($new_val -> debug_str);
$this -> value[] = $new_val;
}
}
}else{
$this -> value = array();
}
return true;
}
// turn soapvals into xml, woohoo!
function serializeval($soapval = false){
if(!$soapval){
$soapval = $this;
}
$this -> debug("serializing '$soapval->name' of type '$soapval->type'");
if(is_int($soapval -> name)){
$soapval -> name = "item";
}
switch($soapval -> type_code){
case 3:
// struct
$this -> debug("got a struct");
if($soapval -> prefix && $soapval -> type_prefix){
$xml .= "<$soapval->prefix:$soapval->name xsi:type=\"$soapval->type_prefix:$soapval->type\">\n";
}elseif($soapval -> type_prefix){
$xml .= "<$soapval->name xsi:type=\"$soapval->type_prefix:$soapval->type\">\n";
}elseif($soapval -> prefix){
$xml .= "<$soapval->prefix:$soapval->name>\n";
}else{
$xml .= "<$soapval->name>\n";
}
if(is_array($soapval -> value)){
foreach($soapval -> value as $k => $v){
$xml .= $this -> serializeval($v);
}
}
if($soapval -> prefix){
$xml .= "</$soapval->prefix:$soapval->name>\n";
}else{
$xml .= "</$soapval->name>\n";
}
break;
case 2:
// array
foreach($soapval -> value as $array_val){
$array_types[$array_val -> type] = 1;
$xml .= $this -> serializeval($array_val);
}
if(count($array_types) > 1){
$array_type = "xsd:ur-type";
}elseif(count($array_types) >= 1){
if($array_val -> type_prefix != ""){
$array_type = $array_val -> type_prefix . ":" . $array_val -> type;
}else{
$array_type = $array_val -> type;
}
}
$xml = "<$soapval->name xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"" . $array_type . "[" . sizeof($soapval -> value) . "]\">\n" . $xml . "</$soapval->name>\n";
break;
case 1:
$xml .= "<$soapval->name xsi:type=\"$soapval->type_prefix:$soapval->type\">$soapval->value</$soapval->name>\n";
break;
default:
break;
}
return $xml;
}
// serialize
function serialize(){
return $this -> serializeval($this);
}
function decode($soapval = false){
if(!$soapval){
$soapval = $this;
}
$this -> debug("inside soapval->decode for $soapval->name of type $soapval->type and value: $soapval->value");
// scalar decode
if($soapval -> type_code == 1){
return $soapval -> value;
// array decode
}elseif($soapval -> type_code == 2){
if(is_array($soapval -> value)){
foreach($soapval -> value as $item){
$return[] = $this -> decode($item);
}
return $return;
}else{
return array();
}
// struct decode
}elseif($soapval -> type_code == 3){
if(is_array($soapval -> value)){
foreach($soapval -> value as $item){
$return[$item -> name] = $this -> decode($item);
}
return $return;
}else{
return array();
}
}
}
// pass it a type, and it attempts to return a namespace uri
function verify_type($type){
global $typemap, $namespaces, $XMLSchemaVersion;
/**
* foreach($typemap as $namespace => $types){
* if(is_array($types) && in_array($type,$types)){
* return $namespace;
* }
* }
*/
foreach($namespaces as $uri => $prefix){
if(is_array($typemap[$uri]) && in_array($type, $typemap[$uri])){
return $uri;
}
}
return false;
}
// alias for verify_type() - pass it a type, and it returns it's prefix
function get_prefix($type){
if($prefix = $this -> verify_type($type)){
return $prefix;
}
return false;
}
function debug($string){
if($this -> debug_flag){
$this -> debug_str .= "soapval: $string\n";
}
}
}
class soap_parser{
function soap_parser($xml, $encoding = "UTF-8"){
// global $soapTypes;
// $this->soapTypes = $soapTypes;
$this -> xml = $xml;
$this -> xml_encoding = $encoding;
$this -> root_struct = "";
// determines where in the message we are (envelope,header,body,method)
$this -> status = "";
$this -> position = 0;
$this -> pos_stat = 0;
$this -> depth = 0;
$this -> default_namespace = "";
$this -> namespaces = array();
$this -> message = array();
$this -> fault = false;
$this -> fault_code = "";
$this -> fault_str = "";
$this -> fault_detail = "";
$this -> depth_array = array();
$this -> debug_flag = true;
$this -> debug_str = "";
$this -> previous_element = "";
$this -> soapresponse = NULL;
$this -> entities = array ("&" => "&", "<" => "<", ">" => ">",
"'" => "'", '"' => """);![]()
Last edited by Vin DSL; 03-05-2006 at 05:42 PM.
DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.
Copyright © 2011 JaguarPC.com
Bookmarks