string(51) "Hata : -6ren">
gpt4 book ai didi

php - PHP Soap的使用

转载 作者:可可西里 更新时间:2023-10-31 23:43:54 25 4
gpt4 key购买 nike

我正在尝试通过 SOAP 将数据插入远程服务器。但出现以下错误:

object(stdClass)#3 (1) { ["DataInsertResult"]=> string(51) "Hata : DI - Value cannot be null. Parameter name: s"

在这里你可以找到我的代码如下:

<?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;
?>

我该如何解决这个问题?

您好,在这里您可以看到我的网络服务提供商的 .n​​et (?) 代码。我如何将其用作 php 代码?

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!";
}

嗨,几天后我得到一个有趣的消息...php_soap 无法连接网络服务但 nusoap 工作正常!下面你可以看到我的代码,但我得到了一个新的错误你可以在代码之后看到错误:)

<?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);
?>

结果:

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

最佳答案

这看起来像是 .NET 错误,您无法在 PHP 端解决它。但可能缺少参数。

例如:如果我的功能是

public void DataInsert(string test1,string s)

如果 s 作为 null 传递,.net 将抛出错误“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>

我认为 Data 或 Token 为 null,你只传递了 1 个参数,现在 Data 为 null,尝试发送 2 个参数,第一个是 token ,第二个是数据。

<?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);

?>

塞拉姆拉尔 (:

关于php - PHP Soap的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5393298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com