在 PHP 中制作请求表单 SOAP 网络服务
Make request form SOAP webservice in PHP
第三方把他的webservice文档给了我测试。我尝试通过将值传递给 header 和 body.
来连接到 soap 网络服务
我想消费的方式是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();
}
我收到这个错误:
Exception Error! Server was unable to process request. ---> Object reference not set to an instance of an object.
谁能帮我解决这个问题。
这是 WSDL:http://191.97.91.43/WSAutorizaciones/WSAutorizacionLaboratorio.asmx?WSDL
终于成功找出了那个SOAP header的问题。我们知道 webservice 已经超过 API,但是一些网站继续使用 webservice (WSL) 来响应客户端。
我所做的唯一更改是在 NAMESPACE
中,只需将其替换为 AuthenticationHeader
中的 url:
错误:
$header = new SoapHeader('NAMESPACE','AuthenticationHeader',$auth,false);
更正:
$header = new SoapHeader('https://arssenasa.gob.do/','AuthenticationHeader',$auth,false);
好的,我看到了一些问题:
- wsdl 变量缺少开头引号
- 在 SoapHeader 中,您必须设置为命名空间“https://arssenasa.gob.do/”
- 你不能直接调用
`$ client-> 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)
"""
}
}
第三方把他的webservice文档给了我测试。我尝试通过将值传递给 header 和 body.
来连接到 soap 网络服务我想消费的方式是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();
}
我收到这个错误:
Exception Error! Server was unable to process request. ---> Object reference not set to an instance of an object.
谁能帮我解决这个问题。
这是 WSDL:http://191.97.91.43/WSAutorizaciones/WSAutorizacionLaboratorio.asmx?WSDL
终于成功找出了那个SOAP header的问题。我们知道 webservice 已经超过 API,但是一些网站继续使用 webservice (WSL) 来响应客户端。
我所做的唯一更改是在 NAMESPACE
中,只需将其替换为 AuthenticationHeader
中的 url:
错误:
$header = new SoapHeader('NAMESPACE','AuthenticationHeader',$auth,false);
更正:
$header = new SoapHeader('https://arssenasa.gob.do/','AuthenticationHeader',$auth,false);
好的,我看到了一些问题:
- wsdl 变量缺少开头引号
- 在 SoapHeader 中,您必须设置为命名空间“https://arssenasa.gob.do/”
- 你不能直接调用
`$ client-> 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)
"""
}
}