Usage of PHP Soap
I'm triying to insert data a remote server via SOAP. But got the error below:
object(stdClass)#3 (1) { ["DataInsertResult"]=> string(51) "Hata : DI - Value cannot be null. Parameter name: s" }
Here you can find tehe my code below:
<?php
$client = new SoapClient("http://www.posta-tr.com/MassDataAccepter/MassDataAccepter.asmx?wsdl");
$connect = $client->Authenticate("accountname", "password");
$send = $client->DataInsert(array(
"idRoot" => array (
"DataToDb" => array(
"Drow" => array (
"FName" => "George",
"LName" => "Houston",
"Email" => "gerorge@emailprovider.com",
"InvitedBy" => "Mary J",
"Job" => "Architect",
"City" => "Newyork",
)
)
)
));
var_dump($send);
echo $client->DataInsertResponse;
?>
How I can solve this problem?
Hi,Here you can see the .net (?) code of my webservice provider. How can i use this as php code?
Webservice Url: http://www.posta-tr.com/MassDataAccepter/MassDataAccepter.asmx?wsdl
protected void btn_Save_Click(object sender, EventArgs e)
{
PwebS.MassDataAccepter mda = new PwebS.MassDataAccepter();
string Result = "Error!";
string Token = mda.Authenticate("user", "pass");
string data = @"<idRoot>
<DataToDb>
<Drow>
<FName>George</FName>
<LName>Houston</LName>
<Email>gerorge@emailprovider.com</Email>
<InvitedBy>Mary J</InvitedBy>
<Job>Architect</Job>
<City>Newyork</City>
</Drow>
</DataToDb>
</idRoot>";
if (Token.Length > 30)
{
Result = mda.DataInsert(Token, data);
}
if (Result.Contains("Inserted : 1"))
lbl_Info.Text = "Data Inserted!";
else if (Result.Contains("Updated : 1"))
lbl_Info.Text = "There is same data in db! Duplicate Data!";
else
lbl_Info.Text = "Error!";
}
Hi, after a few days i got an interesting news... php_soap can not connect the webservice but nusoap works fine! Below you can see my code but i got a new error you can see the error after the code :)
<?PHP
require_once('includes/nusoap/nusoap.php');
$client = new nusoap_client("http://www.posta-tr.com/MassDataAccepter/MassDataAccepter.asmx?wsdl", "wsdl","", "", "", "");
$err = $client->getError();
if ($err) {
echo "<h2>Constructor error</h2><pre>" . $err . "</pre>";
}
$params = array(
'Username'=>'my_username',
'Password'=>'my_password'
);
$result = $client->call("Authenticate", $params, "", "", false, true);
if ($client->fault) {
echo "<h2>Fault</h2><pre>";
print_r($result);
echo "</pre>";
} else {
// Check for errors
$err = $client->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);
$tokenkey = $result['AuthenticateResult'];
echo $tokenkey;
echo "</pre>";
}
}
$veri = "<idRoot>
<DataToDb>
<Drow>
<FName>George</FName>
<LName>Houston</LName>
<Email>gerorge@emailprovider.com</Email>
<InvitedBy>Mary J</InvitedBy>
<Job>Architect</Job>
<City>Newyork</City>
</Drow>
</DataToDb>
</idRoot>";
echo "<hr />";
$send = $client->call("DataInsert",$tokenkey,$veri);
var_dump($send);
?>开发者_如何学Python
The result:
Result
Array
(
[AuthenticateResult] => 92528146-183B-4651-B852-6A1C97F1E908
)
92528146-183B-4651-B852-6A1C97F1E908 //This means we connect the webservice and we got "token"
bool(false) //This means there is an error in data
This looks like a .NET error, you cannot solve it on php side. but maybe a missing parameter.
For example : if my function as
public void DataInsert(string test1,string s)
if s passed as null .net will throw an error as "Value cannot be null. Parameter name: s" }"
http://www.posta-tr.com/MassDataAccepter/MassDataAccepter.asmx?op=DataInsert
<DataInsert xmlns="http://tempuri.org/">
<Token>string</Token>
<Data>string</Data>
</DataInsert>
i think Data or Token is null, you passed only 1 parameter, and now Data is null, try send 2 parameter, first is Token and Second is Data.
<?php
$client = new SoapClient("http://www.posta-tr.com/MassDataAccepter/MassDataAccepter.asmx?wsdl");
$connect = $client->Authenticate("accountname", "password");
$data = "<idRoot>
<DataToDb>
<Drow>
<FName>George</FName>
<LName>Houston</LName>
<Email>gerorge@emailprovider.com</Email>
<InvitedBy>Mary J</InvitedBy>
<Job>Architect</Job>
<City>Newyork</City>
</Drow>
</DataToDb>
</idRoot>";
$send = $client->DataInsert($connect->AuthenticateResult,$data);
var_dump($send);
?>
Selamlar (:
I think the params passed to DataInsert is incorrect, it should be like this:
/* Get token key here */
$token = $tokenKey;
$data = array(
"idRoot" => array (
"DataToDb" => array(
"Drow" => array (
"FName" => "George",
"LName" => "Houston",
"Email" => "gerorge@emailprovider.com",
"InvitedBy" => "Mary J",
"Job" => "Architect",
"City" => "Newyork",
)
)
)
);
$params = array(
'Data' => $data,
'Token' => $token
);
$client = new SoapClient( /* wsdl */ );
$response = $client->DataInsert($params);
精彩评论