【问题标题】:Make request form SOAP webservice in PHP在 PHP 中制作请求表单 SOAP Web 服务
【发布时间】:2021-02-28 00:47:20
【问题描述】:

第三方给了我他的 web 服务文档进行测试。我尝试通过将值传递给标题和正文来连接到肥皂网络服务。

我要使用的方法是ConsultarAfiliado。

肥皂结构是:

            POST /WSAutorizaciones/WSAutorizacionLaboratorio.asmx HTTP/1.1
    Host: 191.97.91.43
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "https://arssenasa.gob.do/ConsultarAfiliado"

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
    <AuthenticationHeader xmlns="https://arssenasa.gob.do/">
    <Cedula>string</Cedula>
    <Password>string</Password>
    <Proveedo>int</Proveedo>
    </AuthenticationHeader>
    </soap:Header>
    <soap:Body>
    <ConsultarAfiliado xmlns="https://arssenasa.gob.do/">
    <TipoDocumento>int</TipoDocumento>
    <NumDocumento>string</NumDocumento>
    </ConsultarAfiliado>
    </soap:Body>
    </soap:Envelope>

我试过这些代码:

    $wsdl =http://191.97.91.43/WSAutorizaciones/WSAutorizacionLaboratorio.asmx?WSDL";
    $client = new SoapClient($wsdl, array('trace' => 1));  // The trace param will show you errors stack

    $auth =array('Cedula' => '001-0945751-5', 'Password' => 'dmfvmxm2', 'Proveedo' => '12077');
     $header = new SoapHeader('NAMESPACE','AuthenticationHeader',$auth,false);
      var_dump($client->__setSoapHeaders($header));

    // web service input params
    $request_param = array('TipoDocumento' => '2', 'NumDocumento' => '021827151');
    $responce_param = null;
    try {
        $responce_param = $client->ConsultarAfiliado($request_param);

        print_r($responce_param->ConsultarAfiliadoResponse);
    } catch (Exception $e) {
        echo "<h2>Exception Error!</h2>";
        echo $e->getMessage();
    }

我收到了这个错误:

异常错误!服务器无法处理请求。 ---> 对象引用未设置为对象的实例。

请有人帮我解决这个问题。
这是 WSDL:http://191.97.91.43/WSAutorizaciones/WSAutorizacionLaboratorio.asmx?WSDL

【问题讨论】:

  • 你真的不应该在 Stackoverflow 上发布密码。
  • 谢谢但有假
  • 根据错误消息,这可能与以下内容重复:stackoverflow.com/questions/779091/…
  • 我看到了,但无法弄清楚我的代码哪里错了。请你帮帮我,你会赢得 50 点赏金
  • 请有人帮我解决这个问题

标签: php web-services soap


【解决方案1】:

最后我成功地找出了那个 SOAP 标头的问题。我们知道 webservice 在 API 上已经过时了,但是一些网站仍然使用 webservice (WSL) 来响应客户端。

我所做的唯一更改是在NAMESPACE 中,只需将其替换为AuthenticationHeader 中的网址即可:

错误:

$header = new SoapHeader('NAMESPACE','AuthenticationHeader',$auth,false);

更正:

$header = new SoapHeader('https://arssenasa.gob.do/','AuthenticationHeader',$auth,false);

【讨论】:

  • 难怪我们错过了它,因为在某些情况下人们使用 NAMESPACE 作为模板参数,它应该是 URL namespace
  • 你是对的人。希望有人能接受我的回答。
【解决方案2】:

好的,我看到了一些问题:

  1. wsdl 变量缺少开头引号
  2. 必须在 SoapHeader 中设置命名空间“https://arssenasa.gob.do/”
  3. 你不能直接调用`$ client-&gt; ConsultAffiliate ($ request_param)`你必须使用```__soapCall``然后指定调用者的名字

我让你在代码下面工作

$wsdl = "http://191.97.91.43/WSAutorizaciones/WSAutorizacionLaboratorio.asmx?WSDL";
        $client = new SoapClient($wsdl, array('trace' => 1));  // The trace param will show you errors stack

        $auth = array('Cedula' => '001-0945751-5', 'Password' => 'dmfvmxm2', 'Proveedo' => '12077');
//        $header = new SoapHeader('NAMESPACE', 'AuthenticationHeader', $auth, false);
        $header = new SoapHeader('https://arssenasa.gob.do/', 'AuthenticationHeader', $auth, false);
        $client->__setSoapHeaders($header);

        // web service input params
        $request_param = array('TipoDocumento' => '2', 'NumDocumento' => '021827151');
        $responce_param = null;
        try {
            $responce_param = $client->__soapCall('ConsultarAfiliado',$request_param);
//            $responce_param = $client->ConsultarAfiliado($request_param);
            var_dump($responce_param);

        } catch (Exception $e) {
            echo "<h2>Exception Error!</h2>";
            echo $e->getMessage();
        }

现在服务回答了我这个问题,但我不知道这是否是预期的答案:

{
  +"ConsultarAfiliadoResult": {#801
    +"Contrato": 0
    +"IdEstado": 0
    +"CodigoFamiliar": 0
    +"IdRegimen": null
    +"Edad": "0"
    +"TipoDocumento": 0
    +"CodigoAfiliado": 0
    +"MensajeAfiliado": """
      System.NullReferenceException: Object reference not set to an instance of an object.
         at SeNaSa.Autorizaciones.Services.AutorizationUtils.DocumentValidations(Int32 TipoDocumento, String NumDocumento)
         at SeNaSa.Autorizaciones.Services.AfiliadoServices.GetAfiliadoInfo(Int32 tipoDocumento, String numDocumento, Int32 Proveedo)
         at WSAutorizaciones.WebService1.ConsultarAfiliado(Int32 TipoDocumento, String NumDocumento)
      """
  }
}

【讨论】:

  • 当我测试 $responce_param = $client->__soapCall('ConsultarAfiliado',$request_param) 时,值都是 0 或 null 但是当我使用 $responce_param = $client->ConsultarAfiliado($请求参数);我得到了所有的结果。
猜你喜欢
  • 2012-05-13
  • 1970-01-01
  • 2016-11-29
  • 1970-01-01
  • 2014-06-18
  • 1970-01-01
  • 2011-11-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多