PHP Soap 的用法

发布于 2024-10-25 04:26:51 字数 4143 浏览 4 评论 0原文

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

object(stdClass)#3 (1) { ["DataInsertResult"]==> string(51) "Hata : DI - 值不能为空。参数名称: 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" => "[email protected]",
            "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>[email protected]</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>[email protected]</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

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" => "[email protected]",
            "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>[email protected]</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>[email protected]</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);
?>

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丢了幸福的猪 2024-11-01 04:26:54

我认为传递给 DataInsert 的参数不正确,应该是这样的:

/* Get token key here */
$token = $tokenKey;

$data = array(
  "idRoot" => array (
      "DataToDb" => array(
          "Drow" => array (
              "FName" => "George",
              "LName" => "Houston",
              "Email" => "[email protected]",
              "InvitedBy" => "Mary J",
              "Job" => "Architect",
              "City" => "Newyork",
          )
      )
  )
);

$params = array(
  'Data' => $data,
  'Token' => $token
);

$client = new SoapClient( /* wsdl */ );
$response = $client->DataInsert($params);

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" => "[email protected]",
              "InvitedBy" => "Mary J",
              "Job" => "Architect",
              "City" => "Newyork",
          )
      )
  )
);

$params = array(
  'Data' => $data,
  'Token' => $token
);

$client = new SoapClient( /* wsdl */ );
$response = $client->DataInsert($params);
千秋岁 2024-11-01 04:26:53

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

例如 :
如果我的函数为

public void DataInsert(string test1,string s)

如果 s 作为 null 传递,.net 将抛出错误,因为“值不能为 null。参数名称:s” }"

http://www.posta-tr.com/MassDataAccepter/MassDataAccepter.asmx?op=DataInsert

 <DataInsert xmlns="http://tempuri.org/">
      <Token>string</Token>
      <Data>string</Data>
    </DataInsert>

我认为数据或者 Token 为 null,您只传递了 1 个参数,现在 Data 为 null,
尝试发送 2 个参数,第一个是 Token,第二个是 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>[email protected]</Email>
            <InvitedBy>Mary J</InvitedBy>
            <Job>Architect</Job>
            <City>Newyork</City>
            </Drow>
            </DataToDb>
            </idRoot>";

$send = $client->DataInsert($connect->AuthenticateResult,$data);
var_dump($send);

?>

塞拉姆拉尔(:

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>[email protected]</Email>
            <InvitedBy>Mary J</InvitedBy>
            <Job>Architect</Job>
            <City>Newyork</City>
            </Drow>
            </DataToDb>
            </idRoot>";

$send = $client->DataInsert($connect->AuthenticateResult,$data);
var_dump($send);

?>

Selamlar (:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文