【问题标题】:PHP counterpart of C# WSDL service query using SOAP使用 SOAP 的 C# WSDL 服务查询的 PHP 对应项
【发布时间】:2013-07-10 15:20:06
【问题描述】:

有一个 WSDL 服务,您可以使用 C# 进行查询,如下所示:

        arameter p1 = new Parameter();
        p1.Name = "$name";
        p1.Value = "thename";

        Parameter p2 = new Parameter();
        p2.Name = "$surname";
        p2.Value = "thesurname";

        Parameter p3 = new Parameter();
        p3.Name = "$birthyear";
        p3.Value = "1990";

        Parameter p4 = new Parameter();
        p4.Name = "$queryno";
        p4.Value = "999999";

        Query query = new Query();
        query.Name = "TheQueryName";
        query.Parameters = new Parameter[] { p1, p2, p3, p4 };

        ServiceReference1.BASEXSoapClient cli = new BASEXSoapClient();
        cli.Open();
        string s = cli.Execute(query);
        cli.Close();

我正在尝试创建此代码的 php 对应项,但查询名称不存在时遇到问题:

<?php
 try
{
$client = new  SoapClient( "http://xxxx/BASEX.asmx?WSDL" );

  $request = array('$name'=>'thename',
                     '$surname'=>'thesurname',
                     '$birthyear'=>'1990',
                     '$queryno'=>'999999');

  $response = $client->TheQueryName($request);    

print_r($response);
}
catch (SoapFault $e)
{
    echo "<pre>";
   print_r($e); exit;
echo "<pre>";

}

?>

这是网络服务:

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <Execute xmlns="xxxxx/basex">
      <query>
        <Name>string</Name>
        <Parameters>
          <Parameter>
            <Name>string</Name>
            <Value>string</Value>
          </Parameter>
          <Parameter>
            <Name>string</Name>
            <Value>string</Value>
          </Parameter>
        </Parameters>
      </query>
    </Execute>
  </soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <ExecuteResponse xmlns="xxxxx/basex">
      <ExecuteResult>string</ExecuteResult>
    </ExecuteResponse>
  </soap12:Body>
</soap12:Envelope>

我被告知我可以使用 SOAP 代替 BASEX 客户端,因为 basex 根本不工作。

【问题讨论】:

    标签: c# php soap wsdl


    【解决方案1】:

    看起来您需要以下结构的参数。此外,您的方法是 Execute,它采用 query['Name'] 参数中的实际名称:

    $request = array(
        'query' => array(
            'Name' => 'TheQueryName',
            'Parameters' => array(
                array('Name' => '$name', 'Value' => 'thename'),
                array('Name' => '$surname', 'Value' => 'thesurname'),
                array('Name' => '$queryno', 'Value' => '999999')
            )
        )
    );
    
    $response = $client->Execute($request);  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 2012-09-11
      • 1970-01-01
      相关资源
      最近更新 更多