SOAP request showing error

Asked

Viewed 803 times

3

I’m trying to perform a SOAP request on http://www.ieptb.com.br/ws/serverTabelionatos.php.

However I am not able to successfully complete the request. The only information you provide me is:

Name: consulta_cenprot
Binding: serverTabelionatosBinding
Endpoint: http://www.ieptb.com.br/ws/serverTabelionatos.php
SoapAction: urn:serverTabelionatos#consulta
Style: rpc
Input:
  use: encoded
  namespace: urn:serverTabelionatos
  encodingStyle: http://schemas.xmlsoap.org/soap/encoding/
  message: consulta_cenprotRequest
  parts:
    tipo_doc: xsd:string
    documento: xsd:string
Output:
  use: encoded
  namespace: urn:serverTabelionatos
  encodingStyle: http://schemas.xmlsoap.org/soap/encoding/
  message: consulta_cenprotResponse
  parts:
    return: xsd:string
Namespace: urn:serverTabelionatos
Transport: http://schemas.xmlsoap.org/soap/http
Documentation: Realiza a consulta de um documento na base de dados

The requisition I’m trying to accomplish is as follows

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "http://www.ieptb.com.br/ws/serverTabelionatos.php",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "\r\n<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<definitions xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:tns=\"urn:serverTabelionatos\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns=\"http://schemas.xmlsoap.org/wsdl/\" targetNamespace=\"urn:serverTabelionatos\">\r\n<types>\r\n<xsd:schema targetNamespace=\"urn:serverTabelionatos\"\r\n>\r\n <xsd:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />\r\n <xsd:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />\r\n <xsd:complexType name=\"vEstados\">\r\n  <xsd:complexContent>\r\n   <xsd:restriction base=\"SOAP-ENC:Array\">\r\n    <xsd:attribute ref=\"SOAP-ENC:arrayType\" wsdl:arrayType=\"tns:vEstados[]\"/>\r\n   </xsd:restriction>\r\n  </xsd:complexContent>\r\n </xsd:complexType>\r\n</xsd:schema>\r\n</types>\r\n\r\n<message name=\"consulta_cenprotRequest\">\r\n  <part name=\"tipo_doc\" type=\"xsd:string\" default=\"CPF\" />\r\n  <part name=\"documento\" type=\"xsd:string\" default=\"CPF AQUI\" /></message>\r\n<portType name=\"serverTabelionatosPortType\">\r\n  <operation name=\"consulta_cenprot\">\r\n    <documentation>Realiza a consulta de um documento na base de dados</documentation>\r\n    <input message=\"tns:consulta_cenprotRequest\"/>\r\n    <output message=\"tns:consulta_cenprotResponse\"/>\r\n  </operation>\r\n</portType>\r\n<binding name=\"serverTabelionatosBinding\" type=\"tns:serverTabelionatosPortType\">\r\n  <soap:binding style=\"rpc\" transport=\"http://schemas.xmlsoap.org/soap/http\"/>\r\n  <operation name=\"consulta_cenprot\">\r\n    <soap:operation soapAction=\"urn:serverTabelionatos#consulta\" style=\"rpc\"/>\r\n    <input><soap:body use=\"encoded\" namespace=\"urn:serverTabelionatos\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"/></input>\r\n    <output><soap:body use=\"encoded\" namespace=\"urn:serverTabelionatos\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"/></output>\r\n  </operation>\r\n</binding>\r\n<service name=\"serverTabelionatos\">\r\n  <port name=\"serverTabelionatosPort\" binding=\"tns:serverTabelionatosBinding\">\r\n    <soap:address location=\"http://www.ieptb.com.br/ws/serverTabelionatos.php\"/>\r\n  </port>\r\n</service>\r\n</definitions>",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "content-type: application/xml",
    "postman-token: 7b5507d8-5af4-a2c2-2831-991f3f313ac8"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

The XML of the request is as follows:

<?xml version="1.0" encoding="ISO-8859-1"?>
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:serverTabelionatos" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:serverTabelionatos">
<types>
<xsd:schema targetNamespace="urn:serverTabelionatos"
>
 <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
 <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
 <xsd:complexType name="vEstados">
  <xsd:complexContent>
   <xsd:restriction base="SOAP-ENC:Array">
    <xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:vEstados[]"/>
   </xsd:restriction>
  </xsd:complexContent>
 </xsd:complexType>
</xsd:schema>
</types>

<message name="consulta_cenprotRequest">
  <part name="tipo_doc" type="xsd:string" default="CPF" />
  <part name="documento" type="xsd:string" default="CPF AQUI" /></message>
<portType name="serverTabelionatosPortType">
  <operation name="consulta_cenprot">
    <documentation>Realiza a consulta de um documento na base de dados</documentation>
    <input message="tns:consulta_cenprotRequest"/>
    <output message="tns:consulta_cenprotResponse"/>
  </operation>
</portType>
<binding name="serverTabelionatosBinding" type="tns:serverTabelionatosPortType">
  <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
  <operation name="consulta_cenprot">
    <soap:operation soapAction="urn:serverTabelionatos#consulta" style="rpc"/>
    <input><soap:body use="encoded" namespace="urn:serverTabelionatos" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
    <output><soap:body use="encoded" namespace="urn:serverTabelionatos" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
  </operation>
</binding>
<service name="serverTabelionatos">
  <port name="serverTabelionatosPort" binding="tns:serverTabelionatosBinding">
    <soap:address location="http://www.ieptb.com.br/ws/serverTabelionatos.php"/>
  </port>
</service>
</definitions>

The error that is returning is as follows:

<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <SOAP-ENV:Fault>
            <faultcode xsi:type="xsd:string">SOAP-ENV:Client</faultcode>
            <faultactor xsi:type="xsd:string"></faultactor>
            <faultstring xsi:type="xsd:string">Operation &apos;&apos; is not defined in the WSDL for this service</faultstring>
            <detail xsi:type="xsd:string"></detail>
        </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

2 answers

5

Looks like you’re mixing the WSDL with your request body.

I believe the body you want to send to call the operation consulta_cenprot would be like the below:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:serverTabelionatos">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:consulta_cenprot soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <tipo_doc xsi:type="xsd:string">CPF</tipo_doc>
         <documento xsi:type="xsd:string">000000191</documento>
      </urn:consulta_cenprot>
   </soapenv:Body>
</soapenv:Envelope>

The WSDL (Web Services Description Language), as its name says, is the description of a web service, a contract, where the available operations are defined, as well as the information that must be sent and will be received in each request/Sponse.

To make calls to the service, the protocol is used SOAP (Simple Object Access Protocol), this protocol has standard structure like the one I showed above.

4


A very common error I see, at least in PHP, are developers trying to use SOAP with Curl or Guzzle and mounting XML in hand.

PHP has a native SOAP client that eliminates all this work.

Just enable or install the SOAP extension (on Windows, uncomment the line extension=php_soap.dll or on Ubuntu apt-get install php-soap) and use the class SoapClient:

<?php

$client = new SoapClient('http://www.ieptb.com.br/ws/serverTabelionatos.php?wsdl', [
    'login' => 'seu_username',
    'password' => 'senha',
]);

var_dump($client->__getFunctions());

By calling $client->__getFunctions() PHP will read all the functions defined in the WSDL and you can call it directly in your code, as if it were a PHP object.

inserir a descrição da imagem aqui

In the case of this webservice, I tried to call the method below:

echo $client->cartorios_participantes('sp');

But as I do not have the credentials to use the service, I received the return Falha na autenticação.

See with the service how you can perform the authentication, my guess is passing as an array the login and the password, but this may vary according to the service.

  • 2

    The answer gets much better when the guy understands PHP :)

  • 1

    No doubt very good clarification

Browser other questions tagged

You are not signed in. Login or sign up in order to post.