Web services - credentials and content type


(Brynlewis) #1

I am trying to configure a ewb servies client.


I have setup a dev version of matrix to do this.



Everything is fine up to generating the wsdl and speicfying the client procedures. However, I have 2 problems when attempting to call any remote procedure.


  1. The server is returning text/html not text/xml


  2. The soap message is always returning this fault:

    <?xml version="1.0" encoding="UTF-8"?>

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body>

    <SOAP-ENV:Fault><faultcode>SERVER</faultcode>

    <faultstring>Either the credentials provided are invalid or this user does not have access to perform this action.</faultstring>

    </SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>



    -I have assigned permissions to the public user.

    -I get the same message when using LoginUser, with valid credentials.

(Benjamin Pearson) #2

[quote]
2. The soap message is always returning this fault:

<?xml version="1.0" encoding="UTF-8"?>

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body>

<SOAP-ENV:Fault><faultcode>SERVER</faultcode>

<faultstring>Either the credentials provided are invalid or this user does not have access to perform this action.</faultstring>

</SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>



-I have assigned permissions to the public user.

-I get the same message when using LoginUser, with valid credentials.

[/quote]



Have you set the status to live? For public access an asset needs Public Read Permission and Live Status.


(Brynlewis) #3

I have got it working by adjusting permissions. Now I don't see how to restrict it to only certain users:


-I created a user and assigned permissions to only that user.

-The client is able to call getAsset() without using credentials.


(Benjamin Pearson) #4

[quote]
I have got it working by adjusting permissions. Now I don't see how to restrict it to only certain users:



-I created a user and assigned permissions to only that user.

-The client is able to call getAsset() without using credentials.

[/quote]



The only it should be to call getAsset() without credentials is with public read and live status, are these still set? If so, try denying public read


(Brynlewis) #5

[quote]
The only it should be to call getAsset() without credentials is with public read and live status, are these still set? If so, try denying public read

[/quote]



If I deny pulic read access, I can't get any operations to work. I have tried a couple of standard HTTP authentication formats but no luck.



Is authentication meant to be passed in the HTTP header? If so, where?


(Benjamin Pearson) #6

[quote]
If I deny pulic read access, I can't get any operations to work. I have tried a couple of standard HTTP authentication formats but no luck.



Is authentication meant to be passed in the HTTP header? If so, where?

[/quote]



Authentication is handled by the SOAP client you are using, and should be transmitted in the SOAP envelope.


(Brynlewis) #7

[quote]
Authentication is handled by the SOAP client you are using, and should be transmitted in the SOAP envelope.

[/quote]





ok. Where/how in the SOAP envelope?


(Benjamin Pearson) #8

[quote]
ok. Where/how in the SOAP envelope?

[/quote]



You pass in the credentials into your SOAP client and the SOAP Client constructs a SOAP envelope which then sends that off to the SOAP Server (in this case, Matrix).


(Brynlewis) #9

Where do I put the credentials into the envelope?


I don't see where they go from the examples, or doco? I understand that the client puts the enveope together, but I'm not clear on how I tell what format etc to use?



Here is the example SOAP envelope from the manual:

POST http://SYSTEM_ROOT_URL/_web_services/soap-server HTTP/1.1

Host: mysite.com

Content-Type: Content-Type: text/xml; charset=utf-8

Content-Length: length

<?xml version="1.0" encoding="utf-8" ?>

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://SYSTEM_ROOT_URL/_web_services/soap-server" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

<soap:Body>

<ns1:CreateAsset>

<TypeCode>AssetType</TypeCode>

<Name>string</Name>

<ParentID>string</ParentID>

<LinkType>LinkType</LinkType>

<LinkValue>string</LinkValue>

<SortOrder>int</SortOrder>

<IsDependant>string</IsDependant>

<IsExclusive>string</IsExclusive>

</ns1:CreateAsset>

</soap:Body>

</soap:Envelope>


(Benjamin Pearson) #10

The example is just a sample of what a SOAP envelope would look like. You would have to consult the documentation of your Soap Client on how to pass credentials, call SOAP functions and debug connections etc. The main point of the example SOAP envelope is to show what variables you need to pass into the function and what result you get in return.


An example of connecting to a SOAP server using PHP and its in-built SoapClient is as follows:

    
    // This is an assetid of the asset to get the URLs from
    $vars = array('AssetID'=> "123");
    
    // Create the client to connect to "some.wsdl" with the user credentials "some_name"/"some_password"
    $client = new SoapClient("some.wsdl", array(
                                                               'login'           => "some_name",
                                                               'password'    => "some_password")
                                      );
    
    // Query the SOAP server
    $result = $client->GetAssetWebPaths($vars);
    
    // Show the results
    echo $result->GetAssetWebPathsResult;


For the documentation of the PHP SoapClient, visit:
http://www.php.net/SoapClien

(Brynlewis) #11

Your example PHP code works whether a valid username/password is used or not, and regardless of what permissions are on the asset.


I assume GetAssetWebPaths does not require permissions.



I have been testing with CloneNode, which does seem to require permissions (I cant be certain of that tho).



The php below doesn't work, regardless of whether valid credentials are used:



ini_set("soap.wsdl_cache_enabled", "0");

$login = Array(

'login' => 'username__',

'password' => 'password__',

);

try {

$client = new SoapClient(asoapserver/soap?WSDL',

$login);

$createInfo = Array (

'TypeCode' => 'folder',

'Name' => 'New Folder3',

'ParentID' => '89817',

'LinkType' => '1',

'IsExclusive' => 'TRUE',

'IsDependant' => 'TRUE',

);

$newAsset = $client->CreateAsset($createInfo);

} catch (SoapFault $e) {

throw new Exception("SOAP Fault Encountered: ".$e->getMessage());

}



The message is 'Unable to Clone asset'


(Benjamin Pearson) #12

[quote]
The message is 'Unable to Clone asset'

[/quote]



The problem is not with your PHP code, you are getting a connection but obviously you cannot clone an asset due to some other reason. For example, you do have write permission to create the new asset, or something like that. Most Get* calls only need read permission, where as creating, updating details usually require write permission.