Rectangle 27 6

a set of PHP classes and No PHP extensions are required

So, if your webhost uses an older version of PHP or does NOT have SoapClient extension installed, you can use this.

To test the webservice, there is an awesome tool: soapUI.

Thanks. Yeah, I've been given that tip, soapUI rocks. But I wanted to know if there's a basic test suite for WSs.

@ign, If you want something basic, go for SoapUI FREE version. That is the lite version of the thing.

I got that already, it's great. What I mean is that perhaps there is a basic array of functionality to do a proof of concept WS. What would that be?

php - Advantages of nuSOAP WebService? - Stack Overflow

php web-services nusoap
Rectangle 27 7

function doAuthenticate(){    
if(isset($_SERVER['PHP_AUTH_USER']) and isset($_SERVER['PHP_AUTH_PW']) )
          {
           //here I am hardcoding. You can connect to your DB for user authentication.    

           if($_SERVER['PHP_AUTH_USER']=="abhishek" and $_SERVER['PHP_AUTH_PW']="123456" )
                return true;
           else
               return  false;                   

           }
}

Call this doAuthenticate function for every operation in server.If it is returning true then only allow the client/user to communicate.

// includes nusoap class
require_once('../lib/nusoap.php');

// Create object
$client = new nusoap_client('<wsdl path>?wsdl', true);
//Setting credentials for Authentication 
$client->setCredentials("abhishek","123456","basic");
..

Hi Neetha please give a response to let me know whether my reply was helpful or not.

so this is just basic security, sent as plain text?

Hi abhishek, how the doAuthenticate() function is referred on server side? do we invoke the function on client side?

Hi its works fine...! please let me know about "digest" and "RELAM" authentications.

web services - PHP nusoap webservice security - Stack Overflow

php web-services nusoap
Rectangle 27 3

You can specify the encoding of NuSOAP streams with the webservices like that :

$client = new nusoap_client($params);
$client->soap_defencoding = 'UTF-8';

php - NuSOAP: how to change content-type of request? - Stack Overflow

php web-services content-type nusoap
Rectangle 27 2

It looks like there's a slight omission in the NuSOAP library... it assumes that the content headers MUST be "text/xml", so if your client is attempting to connect to a service that outputs application/soap+xml headers, you'll end up with errors like:

Response not of type text/xml: application/soap+xml; charset=utf-8

To test this, you may benefit from the following little function pattern, which I used to login to a SOAP service. Remember, print out the client object! You may not actually get a result to look at!

require_once('path/to/downloaded/libraries/nusoap.php');    
var $endpoint = 'https://somedomain.com/path/to/soap/server/Login';
var $client; // the soapclient object

function SOAP_Login()
{
    $this->client = new soapclient($this->endpoint);

    $err = $this->client->getError();
    if ($err) 
    {
        // Display the error
        echo '<p><b>SOAP Constructor error: ' . $err . '</b></p>';
        exit;
        // At this point, you know the call that follows will fail
    }

    $params = array( 
        'some' => 'thing.. depends on what the WSDL expects'
    );

    $result = $this->client->call('someFunction', $params);     

    print_r($result);  // Without the fix, this prints nothing (i.e. false) !!!

    print_r($this->client); // Instead, look at the state of the client object, specifically error_str and debug_str
}

When I printed my $result, I got nothing, but when I printed out the $client object, I could see that there were errors.

The little hack I implemented was in the nusoap.php file, around line 7500. Look for this if-statement:

if (!strstr($headers['content-type'], 'text/xml') && !strstr($headers['content-type'], 'application/soap+xml') ) {
    $this->setError('Response not of type text/xml: ' . $headers['content-type']);
    return false;
}

All this does is it lets NuSOAP handle responses that issue an "application/soap+xml" header (which is a valid xml header).

php - NuSOAP: how to change content-type of request? - Stack Overflow

php web-services content-type nusoap
Rectangle 27 2

I have same problem with nusoap "invalid xml". I'm using the latest php nusoap available here:https://sourceforge.net/projects/nusoapforphp53/ which is for php 5.3, but my php version is running 5.6. Some of the php function used in nusoap.php is deprecated. thats's why showing that error.

<?php 
error_reporting(0);
ini_set('display_errors', 1);

Or find the line which command' deprecated in nusoap.php and replace it with its alternative.

c# - NuSOAP Service Response on Localhost - Stack Overflow

c# php soap
Rectangle 27 4

nusoap_client
$client = new nusoap_client('http://localhost/webServiceResta.php');

php - Help with NuSOAP for a Web Service - Stack Overflow

php web-services xampp nusoap
Rectangle 27 1

This error is exactly what it says: "Couldn't open socket connection to server". Prior SOAP communication client must be able to establish HTTP TCP connection (usually on port 80). This error means that your client is unable to make such connection. It may be caused by many factors: firewall between client and server, server don't like your client, web proxy on the way does not allow you to connect, no routing and so on.

telnet webserviceSite.com 80

and you should see something like:

Connected to webserviceSite.com.
Escape character is '^]'

Then if you type up few characters and hit enter you should get error page from remote server and connection should close. Unless you can get your client box to connect to remote http host reliably your soap call would fail.

i check soap class, but dosnt exist.so i try to use nusoap class.i need to install soap on host server?

php - i got error when call webservice with nusoap - Stack Overflow

php web-services wsdl nusoap
Rectangle 27 4

I could be missing the point, but you never actually assign the returned object to $client:

function getCustomer($ewayId = 9876543211000)
 {
    $url = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?WSDL';  
    $client = new Nusoap_client($url, true);
    $client = $this->setHeaders($client);

    $args['QueryCustomer'] = array('managedCustomerID'=>$ewayId);

    $result = $client->call('QueryCustomer', $args);
    print_r($result);
}

You could also set $client as a class variable if desired or by sending the parameter as a reference.

Looking at the data, I do not know if this matters, but you are using var for your class variable declarations and then using private for the function. If you are using php5 I would stay away from the var:

private $username = 'test@eway.com.au';
private $pw = 'test123';
private $customerId = '87654321';

Use the private or public or protected (whichever your class requires) instead to keep consistency. I doubt this will solve your problem, just something to be conscious about.

Ok, doing some digging of my own, figured this out, you need to encase the actual header you add in a SOAP:Header deal. I tested the below and it was working for me, so give it a try:

private function setHeaders($client)
{
    $headers = <<<EOT
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP:Header>
<eWAYHeader xmlns="http://www.eway.com.au/gateway/managedPayment">
  <eWAYCustomerID>$this->customerId</eWAYCustomerID>
  <Username>$this->username</Username>
  <Password>$this->pw</Password>
</eWAYHeader>
</SOAP:Header>
EOT;
   $client->setHeaders($headers);
   return $client;
}

It did not return any errors. So yea, it seems that is the likely culprit. (Note I also implemented the $client = $this->setHeaders($client); I mentioned above as well.

Alright did a bit of digging and found something that works. Not saying it is right, but yea it works.

private function setHeaders($client)
{
    $headers = <<<EOT
<eWAYHeader xmlns="https://www.eway.com.au/gateway/managedpayment">
  <eWAYCustomerID>$this->customerId</eWAYCustomerID>
  <Username>$this->username</Username>
  <Password>$this->pw</Password>
</eWAYHeader>
EOT;
   $client->setHeaders($headers);
   return $client;
}

 function getCustomer($ewayId = 123456789012)
 {
    $url = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?WSDL';
    $client = new nusoap_client($url);
    $client = $this->setHeaders($client);

    $args['QueryCustomer'] = array('managedCustomerID'=>$ewayId);

    $result = $client->call('QueryCustomer', $args, $namespace='https://www.eway.com.au/gateway/managedpayment', $soapAction='https://www.eway.com.au/gateway/managedpayment/QueryCustomer');

    print_r($result);

    //echo "\n{$client->request}\n"; // This echos out the response you are sending for debugging.
}
namespace
soapAction

Basically, I just looked at that response, and then did some searching to figure out the soapAction, and then just messed with it until the request being sent matched the page you posted. It returns a failed login, but yea. That generally means something is working, and is probably due to the test data. But that gives you a baseline to go off of.

And the $client->request is a handy debugging tool for the future.

Close, but still gives the same error as in my question..

@Click Upvote I think the new update should solve your problem.

@click Well, if you do a var_dump it does show false, which according to the documentation means invalid user data. I do not know if that test information is used for actual testing or more for an example. So if you have actual data to use to test with, try that in place of the test variables.

@Click Upvote Final update for me, but it seems to be doing something instead of returning errors. Good luck from here on.

php - Need help building a webservice called Nusoap - Stack Overflow

php web-services nusoap soapheader
Rectangle 27 4

I could be missing the point, but you never actually assign the returned object to $client:

function getCustomer($ewayId = 9876543211000)
 {
    $url = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?WSDL';  
    $client = new Nusoap_client($url, true);
    $client = $this->setHeaders($client);

    $args['QueryCustomer'] = array('managedCustomerID'=>$ewayId);

    $result = $client->call('QueryCustomer', $args);
    print_r($result);
}

You could also set $client as a class variable if desired or by sending the parameter as a reference.

Looking at the data, I do not know if this matters, but you are using var for your class variable declarations and then using private for the function. If you are using php5 I would stay away from the var:

private $username = 'test@eway.com.au';
private $pw = 'test123';
private $customerId = '87654321';

Use the private or public or protected (whichever your class requires) instead to keep consistency. I doubt this will solve your problem, just something to be conscious about.

Ok, doing some digging of my own, figured this out, you need to encase the actual header you add in a SOAP:Header deal. I tested the below and it was working for me, so give it a try:

private function setHeaders($client)
{
    $headers = <<<EOT
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP:Header>
<eWAYHeader xmlns="http://www.eway.com.au/gateway/managedPayment">
  <eWAYCustomerID>$this->customerId</eWAYCustomerID>
  <Username>$this->username</Username>
  <Password>$this->pw</Password>
</eWAYHeader>
</SOAP:Header>
EOT;
   $client->setHeaders($headers);
   return $client;
}

It did not return any errors. So yea, it seems that is the likely culprit. (Note I also implemented the $client = $this->setHeaders($client); I mentioned above as well.

Alright did a bit of digging and found something that works. Not saying it is right, but yea it works.

private function setHeaders($client)
{
    $headers = <<<EOT
<eWAYHeader xmlns="https://www.eway.com.au/gateway/managedpayment">
  <eWAYCustomerID>$this->customerId</eWAYCustomerID>
  <Username>$this->username</Username>
  <Password>$this->pw</Password>
</eWAYHeader>
EOT;
   $client->setHeaders($headers);
   return $client;
}

 function getCustomer($ewayId = 123456789012)
 {
    $url = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?WSDL';
    $client = new nusoap_client($url);
    $client = $this->setHeaders($client);

    $args['QueryCustomer'] = array('managedCustomerID'=>$ewayId);

    $result = $client->call('QueryCustomer', $args, $namespace='https://www.eway.com.au/gateway/managedpayment', $soapAction='https://www.eway.com.au/gateway/managedpayment/QueryCustomer');

    print_r($result);

    //echo "\n{$client->request}\n"; // This echos out the response you are sending for debugging.
}
namespace
soapAction

Basically, I just looked at that response, and then did some searching to figure out the soapAction, and then just messed with it until the request being sent matched the page you posted. It returns a failed login, but yea. That generally means something is working, and is probably due to the test data. But that gives you a baseline to go off of.

And the $client->request is a handy debugging tool for the future.

Close, but still gives the same error as in my question..

@Click Upvote I think the new update should solve your problem.

@click Well, if you do a var_dump it does show false, which according to the documentation means invalid user data. I do not know if that test information is used for actual testing or more for an example. So if you have actual data to use to test with, try that in place of the test variables.

@Click Upvote Final update for me, but it seems to be doing something instead of returning errors. Good luck from here on.

php - Need help building a webservice called Nusoap - Stack Overflow

php web-services nusoap soapheader
Rectangle 27 2

<?php
class Bills_WS extends CI_controller {
    function __construct() {
        parent::__construct();

        $this->load->library("Nusoap_lib");
        $this->load->model("Member");

        $this->nusoap_server = new soap_server();
        $this->nusoap_server->configureWSDL("Bills_WSDL", "urn:Bills_WSDL");

        $this->nusoap_server->register('hello',                // method name
            array('name' => 'xsd:string'),        // input parameters
            array('return' => 'xsd:string'),      // output parameters
            'urn:Bills_WSDL',                      // namespace
            'urn:Bills_WSDL#hello',                // soapaction
            'rpc',                                // style
            'encoded',                            // use
            'Says hello to the caller'            // documentation
        );
    }

    function index(){

        if($this->uri->rsegment(3) == "wsdl") {
            $_SERVER['QUERY_STRING'] = "wsdl";
        } else {
            $_SERVER['QUERY_STRING'] = "";
        }        

        function hello($name) {
                return 'Hello, ' . $name;
        }
        $this->nusoap_server->service(file_get_contents("php://input"));
    }

}

Make Entry in /config/routes.php

$route['Bills_WS/wsdl'] = "Bills_WS/index/wsdl";

i hope you can see XML on browser now.

<?php
class Soap_client extends CI_controller {

    function __construct() {
        parent::__construct();

        $this->load->library("Nusoap_lib");
        $this->load->helper("url");

    }

    function index() {

        $this->soapclient = new soapclient(site_url('Bills_WS/index/wsdl'), true);

        $err = $this->soapclient->getError();
        if ($err) {
            echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';

        }

        $result = $this->soapclient->call('hello', array('name' => 'Scott'));
        // Check for a fault
        if ($this->soapclient->fault) {
            echo '<h2>Fault</h2><pre>';
            print_r($result);
            echo '</pre>';
        } else {
            // Check for errors
            $err = $this->soapclient->getError();
            if ($err) {
                // Display the error
                echo '<h2>Error</h2><pre>' . $err . '</pre>';
            } else {
                // Display the result
                echo '<h2>Result</h2><pre>';
                print_r($result);
            echo '</pre>';
            }
        }
    }



}
http://localhost/ci_nusoap/index.php/soap_client

i created a separate class library and from there i am calling the method using the class like Master.fruits where Master => class and fruits is => Method, it is working fine in php but in C# it throws error as it should not be master.fruits it should be as masterfruits, any idea

php - nusoap codeigniter webservice server and client - Stack Overflow

php web-services codeigniter nusoap
Rectangle 27 1

$bodyParam = array('urn:operationName'=>array(
    'urn:amount'=>'23232',
    'urn:automati'=>'monUrl',
    'urn:context'=>'',
    'urn:currencyCode'=>'978',
    'urn:customerId'=>'',
    'urn:customerIpAddress'=>'',
    'urn:customerLanguage'=>'fr',
));

xml - Add namespace Prefix in Nusoap PHP - Stack Overflow

php xml soap nusoap
Rectangle 27 9

i know this is an old post, but i ran in to this page looking for an answer.

application/soap+xml is the content-type passed when using SOAP 1.2, text/xml is used with SOAP 1.1,

something like this should do the trick,

$client = new SoapClient("some.wsdl", array('soap_version' => SOAP_1_1));

php - NuSOAP: how to change content-type of request? - Stack Overflow

php web-services content-type nusoap
Rectangle 27 1

Update 5: nusoap actually wraps the request with SOAP-ENV, like:

<SOAP-ENV:Header><eWAYHeader xmlns="https://www.eway.com.au/gateway/managedpayment"> 
      <eWayCustomerID>87654321</eWayCustomerID> 
      <Username>test@eway.com.au</Username> 
      <Password>test123</Password> 
</eWAYHeader></SOAP-ENV:Header>

While in the docs for EWay soap:Header must be used. I couldn't find a mention of the latter in nusoap headers.

Got it. It was a case issue but not there, and their PDF is incorrect.

For anyone that gets this in the future, the PDF says:

<eWAYHeader
  xmlns="http://www.eway.com.au/gateway/managedPayment">
<eWAYHeader
  xmlns="https://www.eway.com.au/gateway/managedpayment">

That's the php soapclient, whereas I'm calling the Nusoap soapclient.

class nusoap_client
Array ( [faultcode] => soap:Client [faultstring] => Server did not recognize the value of HTTP Header SOAPAction: . [detail] => )

Still getting the same error, however if I set $wsdl to true, i.e $client = new nusoap_client($url, true);, I get a different error.. see my edit to the question

php - Need help building a webservice called Nusoap - Stack Overflow

php web-services nusoap soapheader
Rectangle 27 1

Update 5: nusoap actually wraps the request with SOAP-ENV, like:

<SOAP-ENV:Header><eWAYHeader xmlns="https://www.eway.com.au/gateway/managedpayment"> 
      <eWayCustomerID>87654321</eWayCustomerID> 
      <Username>test@eway.com.au</Username> 
      <Password>test123</Password> 
</eWAYHeader></SOAP-ENV:Header>

While in the docs for EWay soap:Header must be used. I couldn't find a mention of the latter in nusoap headers.

Got it. It was a case issue but not there, and their PDF is incorrect.

For anyone that gets this in the future, the PDF says:

<eWAYHeader
  xmlns="http://www.eway.com.au/gateway/managedPayment">
<eWAYHeader
  xmlns="https://www.eway.com.au/gateway/managedpayment">

That's the php soapclient, whereas I'm calling the Nusoap soapclient.

class nusoap_client
Array ( [faultcode] => soap:Client [faultstring] => Server did not recognize the value of HTTP Header SOAPAction: . [detail] => )

Still getting the same error, however if I set $wsdl to true, i.e $client = new nusoap_client($url, true);, I get a different error.. see my edit to the question

php - Need help building a webservice called Nusoap - Stack Overflow

php web-services nusoap soapheader
Rectangle 27 2

A little bit of googling with that particular error message reveals that it might be related to the Soap server answering in Soap version 1.2, while the default setting in PHP is Soap version 1.1.

array('soap_version'=> SOAP_1_2)

xml - PHP SoapClient Version Mismatch - Stack Overflow

php xml soap nusoap
Rectangle 27 2

A little bit of googling with that particular error message reveals that it might be related to the Soap server answering in Soap version 1.2, while the default setting in PHP is Soap version 1.1.

array('soap_version'=> SOAP_1_2)

xml - PHP SoapClient Version Mismatch - Stack Overflow

php xml soap nusoap
Rectangle 27 2

$ns = "http://tempuri.org/"

//Body of the Soap Header.
$headerbody = array('UserName' => $yourUsername,
                    'Password' => $yourPassword,
              );

//Create Soap Header.       
$header = new SOAPHeader($ns, 'AuthHeader', $headerbody);       

//set the Headers of Soap Client.
$soap_client->__setSoapHeaders($header);

Ok so this is a first. even though i have the SOAPClient enabled i am getting this error Undefined variable: soap_client in C:\wamp\www\soap1.php on line 14 and Fatal error: Call to a member function __setSoapHeaders() on a non-object in C:\wamp\www\soap1.php on line 14

well, you actually need to have the soap client instance, my code is partial. Post your code without the real data and we'll try to see what you are doign wrong.

for me the WSDL does not even load from the url.

Thank you so much for ure help. i figured it out and posted the solution above. THANK YOU!

Consume a .Net web service using PHP - Stack Overflow

php web-services soap soap-client nusoap
Rectangle 27 1

PHP ob_start() function works by catching all output to buffer and then implicitly output this buffer on script end. You may execute ob_end_clean() to discard (clean) buffer.

PS. Function ob_implicit_flush() has different meaning. It just flush buffer on every output call (like print or echo), and do not have effect on script finish.

So you're saying that even without any flush command or implicit flush option turned on, when it reaches the end of the php script it will output the buffer anyway?

Thanks! So why were people asking me if I knew how to search the file? Seems weird that I'd take such crap for asking this question seeing that it's a legit question.

php - ob_start() without an ob_flush() - Stack Overflow

php nusoap output-buffering
Rectangle 27 2

Because this was the only header I had to set, I was able to fix it using the following code.

$headers[] = new SoapHeader('http://www.qpricer.com/Services/Pricing','Identity token="123456789"',null);

This produced the following XML

<ns1:Identity token="123456789"/>

and it worked!

PHP Soap Header help - Stack Overflow

php soap nusoap soap-client soapheader