1

[已解决] 我正在尝试使用-this wsdl-中描述的方法GeneraTimbre

<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/>...

我的代码是这样的:

$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));

这是我使用 __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>

我从服务器收到“空缓冲区”响应,我认为这是因为我没有看到从编码行发送到函数的数据:

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

PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4gDQo8Y2ZkaTpDb21wcm9iYW50ZSB4bWxuczpjZmRpPSJodHRwOi8vd3d3LnNhdC5nb2IubXgvY2ZkLzMiIHhtb....)

由于我是 SOAP 新手,我猜该字符串应该在请求中的某个位置,可以吗?还是我在代码中做错了什么?

- - - - - - - - - - - - -解决方案 - - - - - - - - - - -

所以我联系了负责人并询问“你希望在你的 WS 中得到什么”,我用这个函数解决了这个问题(在一个名为 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(); 
} 
    }
4

1 回答 1

0

尝试这个:

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

我也是 SOAP 新手,我在同一个 WS 中工作,但我还没有成功。

于 2013-10-09T21:43:55.247 回答