How do I request an xml via Soap in php?

Asked

Viewed 197 times

1

I’m having trouble sending an XML to another TOTVS server, I need to do it in php using Soap but I’m having an invalid argument error but testing Soapui how the same XML can forward and in php gives the error below:

Error: Soapfault Exception: [Sender] WEBSERVICE ERROR : Argument Missing : Required field INMSG not found. in C: laragon www webservice soapTest.php:164 Stack trace: #0 C: laragon www webservice soapTest.php(164): Soapclient->__soapCall('RECEIVEMESSAGE', Array) #1 {main}

below follows the php code as the xml I’m trying to pass

wsdl   = "http://Server/ws/EAISERVICE.apw?WSDL"; 
$client = new SoapClient($wsdl, array(  'soap_version' => SOAP_1_1, 'trace' => true,  )); 
try {

    $xml = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:tot='http://www.totvs.com/'>
   <soapenv:Header/>
   <soapenv:Body>
      <tot:RECEIVEMESSAGE>
         <tot:INMSG><![CDATA[
      '<TOTVSIntegrator>  
    <GlobalProduct>PROTHEUS</GlobalProduct>  
    <GlobalFunctionCode>EAI</GlobalFunctionCode>  
    <GlobalDocumentFunctionCode>STINTP02</GlobalDocumentFunctionCode>  
    <GlobalDocumentFunctionDescription>CADASTRO CLIENTE</GlobalDocumentFunctionDescription>  
    <DocVersion>1.3</DocVersion>  
    <DocDateTime>2019-10-07T14:00:42Z</DocDateTime>  
    <DocIdentifier>5dd6a08b-5dd6-5dd6-5dd6-5dd6a08b4318</DocIdentifier>  
    <DocCompany>09</DocCompany>  
    <DocBranch>0901</DocBranch>  
    <DocName>AURORA TERMINAIS</DocName>  
    <DocFederalID>01777936000196</DocFederalID>  
    <DocType>1</DocType>  
    <Message>  
        <Layouts>  
            <Identifier>STINTP02</Identifier>  
            <Version>1.0</Version>  
            <FunctionCode>U_STINTP02</FunctionCode>  
            <Content>  
                <MATA030 version='1.01' Operation='I'>  
                    <MATA030_SA1 modeltype='FIELDS'>  
                        <A1_XCOD>  
                            <value>XPTO0003</value>  
                        </A1_XCOD>  
                        <A1_PESSOA>  
                            <value>J</value>  
                        </A1_PESSOA>  
                        <A1_NOME>  
                            <value>GS ANUNCIACAO - ME</value>  
                        </A1_NOME>  
                        <A1_NREDUZ>  
                            <value>A.G.S</value>  
                        </A1_NREDUZ>  
                        <A1_TIPO>  
                            <value>F</value>  
                        </A1_TIPO>
                        <A1_END>  
                            <value>RUA 32 QD A43, 15</value>  
                        </A1_END>
                        <A1_EST>  
                            <value>AM</value>  
                        </A1_EST>  
                        <A1_COD_MUN>  
                            <value>02603</value>  
                        </A1_COD_MUN>  
                        <A1_MUN>  
                            <value>MANAUS</value>  
                        </A1_MUN>  
                        <A1_BAIRRO>  
                            <value>PLANALTO</value>  
                        </A1_BAIRRO>  
                        <A1_CEP>  
                            <value>69044210</value>  
                        </A1_CEP>
                        <A1_COMPLEM>  
                            <value>55</value>  
                        </A1_COMPLEM>  
                        <A1_DDD>  
                            <value>92</value>  
                        </A1_DDD>  
                        <A1_TEL>  
                            <value>33031510</value>  
                        </A1_TEL>  
                        <A1_PAIS>  
                            <value>105</value>  
                        </A1_PAIS>  
                        <A1_PAISDES>  
                            <value>BRASIL</value>  
                        </A1_PAISDES>  
                        <A1_CGC>  
                            <value>16604094000148</value>  
                        </A1_CGC>  
                        <A1_INSCR>  
                            <value>ISENTO</value>  
                        </A1_INSCR>  
                        <A1_INSCRM>  
                            <value>22581701</value>  
                        </A1_INSCRM>  
                        <A1_CONTA>  
                            <value>11220001</value>  
                        </A1_CONTA>  
                        <A1_RECISS>  
                            <value>1</value>  
                        </A1_RECISS>  
                        <A1_CODPAIS>  
                            <value>01058</value>  
                        </A1_CODPAIS>  
                        <A1_TPESSOA>  
                            <value>CI</value>  
                        </A1_TPESSOA>  
                        <A1_RECINSS>  
                            <value>N</value>  
                        </A1_RECINSS>
                        <A1_RECCOFI>  
                            <value>N</value>  
                        </A1_RECCOFI>  
                        <A1_RECCSLL>  
                            <value>N</value>  
                        </A1_RECCSLL>  
                        <A1_RECPIS>  
                            <value>N</value>  
                        </A1_RECPIS>  
                        <A1_MSBLQL>  
                            <value>2</value>  
                        </A1_MSBLQL>  
                        <A1_RECIRRF>  
                            <value>2</value>  
                        </A1_RECIRRF>  
                        <A1_XORIEN>  
                            <value>1</value>  
                        </A1_XORIEN>  
                        <A1_XFORMPG>  
                            <value>1</value>  
                        </A1_XFORMPG>
                        <A1_LOJA>  
                            <value>TESTE</value>  
                        </A1_LOJA_>
                        <A1_RISCO>  
                            <value>A</value>  
                        </A1_RISCO>
                        <A1_EMAIL>  
                            <value>[email protected]</value>  
                        </A1_EMAIL>  
                        <A1_XMAILCB>  
                            <value>[email protected];email2</value>  
                        </A1_XMAILCB>
                        <A1_ENDCOB>  
                            <value>RUA ABC, 275</value>  
                        </A1_ENDCOB>
                        <A1_BAIRROC>  
                            <value>BAIRRO COBRANCA</value>  
                        </A1_BAIRROC>  
                        <A1_CEPC>  
                            <value>66610190</value>  
                        </A1_CEPC>  
                        <A1_MUNC>  
                            <value>BELEM</value>  
                        </A1_MUNC>  
                        <A1_ESTC>  
                            <value>PA</value>  
                        </A1_ESTC>  
                    </MATA030_SA1>  
                </MATA030>  
            </Content>  
        </Layouts>  
    </Message>  
</TOTVSIntegrator>']]></tot:INMSG>
      </tot:RECEIVEMESSAGE>
   </soapenv:Body>
</soapenv:Envelope>";

    $args = array(new SoapVar($xml, XSD_ANYXML));    
    $res  = $client->__soapCall('RECEIVEMESSAGE', $args);
    //return $res;
} 
catch (SoapFault $e) {
    echo "Error: {$e}";
}

echo "<hr>Last Request";
echo "<pre>", htmlspecialchars($client->__getLastRequest()), "</pre>";

echo "<hr>Last Response";
echo "<pre>", htmlspecialchars($client->__getLastResponse()), "</pre>";

someone could help me with that if there’s something wrong with the code because I’m not very familiar with Soap.

  • Welcome to Stack Overflow! Your question seems to have some problems and your experience here in Stack Overflow may not be the best because of this. We want you to do well here and get what you want, but for that we need you to do your part. Here are some guidelines that will help you: Stack Overflow Survival Guide in English.

No answers

Browser other questions tagged

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