简体   繁体   中英

PHP SOAP Request without parameter

[SOLVED] I'm Trying to consume the method GeneraTimbre as described in -this wsdl- :

<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="https://test.timbrado.com.mx/cfdi/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="https://test.timbrado.com.mx/cfdi/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="https://test.timbrado.com.mx/cfdi/">
<s:element name="GeneraTimbre">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="xmlBytes" type="s:base64Binary"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GeneraTimbreResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GeneraTimbreResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="AuthenticationHeader" type="tns:AuthenticationHeader"/>
<s:complexType name="AuthenticationHeader">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="UserName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string"/>
</s:sequence>
<s:anyAttribute/>...

my code goes like this:

$timbrador=new SoapClient("http://test.timbrado.com.mx/cfdi/wsTimbrado.asmx?wsdl");
$header = array('UserName' => $user,'Password' => $pass);
$Soapheader = new SOAPHeader('https://test.timbrado.com.mx/cfdi/', 'AuthenticationHeader', $header);
$timbrador->__setSoapHeaders($Soapheader); 
$xml="An Xml String....";
$cfdi=$timbrador->GeneraTimbre(base64_encode($xml));

this is the request i get with __getLastRequest():

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://test.timbrado.com.mx/cfdi/">
    <SOAP-ENV:Header><ns1:AuthenticationHeader><ns1:UserName>0000000001</ns1:UserName><ns1:Password>pwd</ns1:Password></ns1:AuthenticationHeader></SOAP-ENV:Header>
        <SOAP-ENV:Body><ns1:GeneraTimbre/></SOAP-ENV:Body>
</SOAP-ENV:Envelope>

i'm receiving an "Empty buffer" response from the server, ii'm thinking it's because i don't see the data sent to the function from the encoding line:

base64_encode($xml); (if i echo it, i get a long string like this:  

PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4gDQo8Y2ZkaTpDb21wcm9iYW50ZSB4bWxuczpjZmRpPSJodHRwOi8vd3d3LnNhdC5nb2IubXgvY2ZkLzMiIHhtb.... )

Since I'm new to SOAP, I'm guessing that string should be somewhere on the request, is that ok? or am I doing something wrong in the code?.

-------------------------Solution----------------------

So i contacted the ones in charge and asked "what do you expect to get in your WS", and i solved the problem with this function (in a class called timbrador)

    public function timbrar($xml)//receives the xml string to be sent
    {
        $request='<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:cfdi="https://test.timbrado.com.mx/cfdi/">
   <soap:Header>
      <cfdi:AuthenticationHeader>
 <cfdi:UserName>0000000001</cfdi:UserName>
           <cfdi:Password>pwd</cfdi:Password>
      </cfdi:AuthenticationHeader>
   </soap:Header>
   <soap:Body>
      <cfdi:GeneraTimbre>
 <cfdi:xmlBytes>'.base64_encode($xml).'</cfdi:xmlBytes>
      </cfdi:GeneraTimbre>
   </soap:Body>
</soap:Envelope>';
        try
        {
        $cfdi=$this->timbrador->
        __doRequest($request,"http://test.timbrado.com.mx/cfdi/wsTimbrado.asmx",
        "http://test.timbrado.com.mx/cfdi/wsTimbrado.asmx?op=GeneraTimbre",
        SOAP_1_2,
        0);
        $this->resultado_timbre=$cfdi;
        }catch(SoapFault $fault){ 
            echo "REQUEST:<br>" . htmlentities(str_ireplace('><', ">\n<", $this->timbrador->__getLastRequest())) . "<br>";
            echo "Response:<br>" . htmlentities(str_ireplace('><', ">\n<", $this->timbrador->__getLastResponse())) . "<br>";
         $fault->getMessage(); 
} 
    }

Try this:

$params = array('xmlBytes'=>base64_encode(file_get_contents($xml)));
$result = $client->GeneraTimbre($params);

I'm new to SOAP too, I works in de the same WS, but I have a non-success yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM