I have sharepoint installed in my local windows server available through LAN. Now i am running a web-service in php on my local apache server like this:
<?php
//Authentication details
$authParams = array('login' => 'username', 'password' => 'password'); \
$listName = "TestList1";
$rowLimit = '150';
$wsdl = "http://www.blah.com/sharepoint/ListsWSDL.wsdl";
//Creating the SOAP client and initializing the GetListItems method parameters
$soapClient = new SoapClient($wsdl, $authParams);
$params = array('listName' => $listName, 'rowLimit' => $rowLimit);
//Calling the GetListItems Web Service
$rawXMLresponse = null;
try{
$rawXMLresponse = $soapClient->GetListItems($params)->GetListItemsResult->any;
}
catch(SoapFault $fault){
echo 'Fault code: '.$fault->faultcode;
echo 'Fault string: '.$fault->faultstring;
}
echo '<pre>' . $rawXMLresponse . '</pre>';
//Loading the XML result into parsable DOM elements
$dom = new DOMDocument();
$dom->loadXML($rawXMLresponse);
$results = $dom->getElementsByTagNameNS("#RowsetSchema", "*");
//Fetching the elements values. Specify more attributes as necessary
foreach($results as $result){
echo $result->getAttribute("ows_LinkTitle")."<br/>";
}
unset($soapClient);
?>
<body>
</body>
</html>
But control is going to catch block with error displayed as:
Fault code: HTTPFault string: Unauthorized
Why is this happening?
First check the WSDL file, the server location is in the wsdl file, right at the bottom. Please make sure this server location is correct.
Please activate "Basic authentication" (in IIS6) for this sharepoint site you are trying to access.
Have you enabled the basic authentication in IIS ?
Look at this link :
http://blogs.iis.net/nitashav/archive/2010/02/22/iis6-0-ui-vs-iis7-x-ui-series-basic-authentication.aspx
Check your credentials.
Try to change IIS Authentication Settings to Kerberos.
Related
I am using SOAP to call a web servicefrom a Linux Centos 6 server and a php client. In this week I have been getting could not connect to host error from soapCall method. My code is as below and I have not changed it at all for some months but recently it gets this error most of the time. I have read most answers to related questions here but my problem have not been solved.
$wsdl="http://x.x.x.x:x/gw/services/Service?wsdl";
//Set key as HTTP Header
$aHTTP['http']['header'] = "key:" .$key ."\r\n";
$context = stream_context_create($aHTTP);
try
{
$client = new SoapClient($wsdl,array("soap_version" => SOAP_1_2,'trace' => 1,"stream_context" => $context));
}
catch(Exception $e)
{
return "something";
}
//I make $parametrs
try
{
$res = $client->__soapCall("send",array($parametrs));
}
catch(Exception $e)
{
print_r($e->getMessage()); //Most of the time it prints could not connect to host
}
I changed SOAP from _1_1 to _1_2 but nothing changed.
This is how I call SOAP webservice, please note Service?wsdl should be Service.wsdl
Example
//Initialize values
$wsdl = "Service.wsdl";
$url = "http://x.x.x.x:x/gw/services/";
$username = "********"; //add username
$password = "********"; //add password
$client = new SoapClient("$url".$wsdl);
$params = array(
"username"=>$username,
"password"=>$password
);
$response = $client->UserLogIn($params); //UserLogIn is the function name
var_dump($response); // to see webservice response
I'm trying to connect to a web service using PHP's soap client which I can successfully do using Visual Studio, pressing F5 and running the page locally which works a treat.
As soon as I upload the exact same file to my apache web host, I keep getting the error: "failed to load external entity".
Here's my code with the credentials and url taken out...
Any ideas?
<?php
header("Access-Control-Allow-Origin: http://example.com");
header("Access-Control-Request-Method: GET,POST");
ini_set('display_errors', true);
ini_set("soap.wsdl_cache_enabled", "0");
error_reporting(E_ALL);
try
{
$soapclient = new SoapClient('http://example.com');
$params = array ('SystemID' => 'testID','Username' => 'test', 'Password' => 'test');
$response = $soapclient->GetEngineerList($params);
print_r($response);
}
catch(SoapFault $e)
{
print_r($e);
}
strings are not read twice and parsed in single quotes
$soapclient = new SoapClient('$url');
try
$soapclient = new SoapClient($url);
also...do you have $url = ''; anywhere?
UPDATE 1
please try using basic auth to get to your wsdl:
$login = 'bert';
$password = 'berts password';
$client = new SoapClient(
'http://' . urlencode($login) . ':' . urlencode($password) . '#www.server.com/path/to/wsdl',
array(
'login' => $login,
'password' => $password
)
);
I have a function which handles the SOAP based web service.
When I run the function via URL I am getting XML response. but when I run the function through CRON I am not getting xml response.
<?php
$logFile = 'checking'.date('Y-m-d').'.log';
$client = new SoapClient("http://DOMAIN/services/weburl?wsdl",array( "trace" => true, 'use' => SOAP_LITERAL));
$params = array('username' => 'username', 'Password' => 'password', 'delatdate' => '17/06/2015 18:00:00');
try{
$response = $client>-productOnHand($params);
} catch(SoapFault $e){
echo $e->faultcode; echo '<br />';
echo $e->getMessage(); echo '<br />';
}
require_once 'app/Mage.php';
Mage::app();
Mage::log(print_r($response, true), null, $logFile);
Mage::log(print_r($client->__getLastResponse(), true), null, $logFile);
?>
If I run this web page via URL I am getting valid xml response. But when this page is being called through CRON I am not getting valid response.
I fixed this issue.
Before default_socket_timeout was set as 60. I raised it as 600. Now I could able to receive.
I used following code to get list for sharepoint 2010 api
//Authentication details
$authParams = array('login' => "username",
'password' => 'password');
////
///* A string that contains either the display name or the GUID for the list.
// * It is recommended that you use the GUID, which must be surrounded by curly
// * braces ({}).
// */
$listName = "listname";
$rowLimit = '10';
//
///* Local path to the Lists.asmx WSDL file (localhost). You must first download
// * it manually from your SharePoint site (which should be available at
// * yoursharepointsite.com/subsite/_vti_bin/Lists.asmx?WSDL)
$wsdl = "http://localhost/sharepoint/Lists.asmx.xml";
$rawXMLresponse = null;
try{
// //Creating the SOAP client and initializing the GetListItems method parameters
$soapClient = new SoapClient($wsdl, $authParams);
$params = array('listName' => $listName,
'rowLimit' => $rowLimit);
//Calling the GetListItems Web Service
$rawXMLresponse = $soapClient->GetListItems($params)->GetListItemsResult->any;
}
catch(SoapFault $fault){
echo 'Fault code: '.$fault->faultcode;
echo 'Fault string: '.$fault->faultstring;
}
echo '<pre>' . $rawXMLresponse . '</pre>';
//
////Loading the XML result into parsable DOM elements
$dom = new DOMDocument();
$dom->loadXML($rawXMLresponse);
$results = $dom->getElementsByTagNameNS("#RowsetSchema", "*");
//Fetching the elements values. Specify more attributes as necessary
foreach($results as $result){
echo $result->getAttribute("ows_LinkTitle")."<br/>";
}
unset($soapClient);
and getting error
Fault code: HTTPFault string: Unauthorized
I used some third party libraries like https://github.com/thybag/PHP-SharePoint-Lists-API
but still no luck.
Anyone worked on it, Please suggest me some method to get data from share point 2010 api
<?
include_once("$SrvRoot/library/lib_base.php");
require_once('twitteroauth.php');
require_once('../config/twconfig.php');
// I defined YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET,
YOUR_ACCESS_TOKEN, YOUR_ACCESS_TOKEN_SECRET in twconfig.php
$connection = new TwitterOAuth("YOUR_CONSUMER_KEY", "YOUR_CONSUMER_SECRET",
"YOUR_ACCESS_TOKEN", "YOUR_ACCESS_TOKEN_SECRET");
$param = array( 'q' => 'mytweetttt' );
$tw_data = $connection->get('search/tweets', $param);
Util::dumpArray($tw_data); // It's same with echo "<pre>"; var_dump($tw_data); echo "</pre>";
?>
I coded like this, but I got "Invalid or expired token" message.
When I tested using OAuth tools using cURL command on linux server, There's working.
Why TwitterOauth shows that message? Please give me advice what's the problem.
Because you pass strings instead of variables/constants?
$connection = new TwitterOAuth("YOUR_CONSUMER_KEY", "YOUR_CONSUMER_SECRET",
"YOUR_ACCESS_TOKEN", "YOUR_ACCESS_TOKEN_SECRET");
If you defined constants it should be:
$connection = new TwitterOAuth(YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET,
YOUR_ACCESS_TOKEN, YOUR_ACCESS_TOKEN_SECRET);