Hi,

I am new to SOAP and getting this error

" RESULTS: Array ( [faultcode] => Client [faultactor] => [faultstring] => Could not authenticate SOAP request: Could not retrieve authentication credentials from SOAP header [detail] => )"

The cURL PHP extension is required for NuSOAP to make a connection over SSL

<?
require_once "nusoap/nusoap.php";
/**
* @file
* Example code to access the Omniture Web Services for Administration Console
* and retrieve the current token count.
*
* @author Omniture <clientcare@omniture.com>
* @copyright 2006 Omniture, Inc. All Rights Reserved
*/
// reference the downloaded WSDL
define('WSDL_DOCUMENT', "./Omniture_wsdl.xml");

// seed random
list($usec, $sec) = explode(' ', microtime());
srand((float) $sec + ((float) $usec * 100000));

// SOAP login credentials
$username = "provided";


$secret = '*provided;

function get_header($username, $secret)
{
// Create a unique identifier, a.k.a. nonce.
// This example is used for simplicity in demonstration. A method
// that guarantees uniqueness should be used in a production environment.

$nonce = md5(rand());
$created = date("Y-m-d H:i:s");
$combo_string = $nonce . $created . $secret;

$sha1_string = sha1($combo_string);


$password = base64_encode($sha1_string);

$headers = '<wsse:Security SOAP-ENV:mustUnderstand="1">

<wsse:UsernameToken wsu:Id="User">
<wsse:Username>'.$username.'</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-
200401-wss-username-token-profile-1.0#PasswordDigest">'.$password.'</
wsse:Password>
<wsse:Nonce>'.$nonce.'</wsse:Nonce>
<wsu:Created>'.$created.'</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>';

return $headers;

}

// Create nuSOAP client
$client = new soapclient(WSDL_DOCUMENT, TRUE);

// handle client setup error
if($err = $client->getError()) {
echo "ERROR:".$err."\n";
exit();
}
// call Omniture Web services function
$result = $client->call('Company.GetTokenCount', // function name
array('auth_key' => $username), // parameters
'http://omniture.com', // namespace
'', // SOAP Action

get_header($username, $secret)); // security header
// Display results
echo "RESULTS:\n";
print_r($result);
echo "\n";

?>

Hi everybody

I have found a way to do a personal authentication on a web service. In the soap header message, you can set nodes with that information. So, each time the client consume a web service, he/she must athuenticate him/her self. Now, the problem is that don't work forme. T-T

Check the exaple at the bottom, http://msdn.microsoft.com/es-es/library/8728chd5.aspx

Now, I did a web service that brings the user name seted inside the header, the problem is that is not founded.


This. is my web service:


MyWebService.asmx

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

' Define a SOAP header by deriving from the SoapHeader base class.
Public Class Header : Inherits SoapHeader
    Public Username As String
    Public Password As String
End Class

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.

<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class MyWebService
    ' Add a member variable of the type deriving from SoapHeader.
    Public myHeaderMemberVariable As Header

    ' Apply a SoapHeader attribute.
    <WebMethod(), SoapHeader("myHeaderMemberVariable")> _
    Public Function MyWebMethod() As String
        ' Process the SoapHeader.
        Return myHeaderMemberVariable.Username
    End Function
End Class

My test file:

test1.php

<?php
    require_once('nusoap_0-7-3/lib/nusoap.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Probando los Web Services desde PHP</title>
    </head>
    <body>
<?php
    $wsdl = 'http://localhost/ws/MyWebService.asmx?WSDL';
    $method = 'MyWebMethod';
    $params = array();
    $client = new nusoap_client($wsdl, 'wsdl');
    //$client->response_timeout = 600;

    $client->soap_defencoding = 'UTF-8';
    $client -> setHeaders('   
        <Header>
            <Username>[B]myUserName[/B]</Username>
            <Password>myPassword</Password>
        </Header>
    ');
    $err = $client->getError();
    //echo "<br/> proxyport =".htmlspecialchars($client->$proxyhost)."<br/>";

    if ($err) {
        echo '<h2>Error del contructor</h2><pre>' . $err . '</pre>';
        echo '<h2>Debug:</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
        exit();
    }
    $result = $client->call($method, $params);

    if ($client->fault) {
        echo '<h2>Fault</h2><pre>'; print_r($result); echo '</pre>';
    } else {
        $err = $client->getError();
        if ($err) {
            echo '<h2>Error</h2><pre>' . $err . '</pre>';
        } else {
            echo '<h2>Result</h2><pre>'; print_r($result); echo '</pre>';
        }
    }
    echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
?>
    </body>
</html>

My Issue 0_o

Fault

Array
(
[faultcode] => soap:Server
[faultstring] => System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.

at meals_ws_application.MyWebService.MyWebMethod() in C:\Documents and Settings\ingenieria\Mis documentos\Visual Studio 10\Projects\ws\meals-ws-application\MyWebService.asmx.vb:line 25
--- End of inner exception stack trace ---

[detail] =>
)

Request

POST /ws/MyWebService.asmx HTTP/1.0

Host: localhost
User-Agent: NuSOAP/0.7.3 (1.114)
Content-Type: text/xml; charset=UTF-8
SOAPAction: "http://tempuri.org/MyWebMethod"

Content-Length: 554

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns8315="http://tempuri.org"><SOAP-ENV:Header>

<Header>
<Username>myUserName</Username>
<Password>myPassword</Password>
</Header>
</SOAP-ENV:Header><SOAP-ENV:Body><MyWebMethod xmlns="http://tempuri.org/"></MyWebMethod></SOAP-ENV:Body></SOAP-ENV:Envelope>

I just want that the web service return myUserName, that's it T-T
If it works I could set some encripted information. All your posts are wellcome.


Regards


Jorge Andrés Cañón Sierra
Ingenierio de Sistemas

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.