没有参数的PHP SOAP请求

时间:2013-10-08 23:48:05

标签: php web-services soap wsdl

[求助]我正在尝试使用-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(); 
} 
    }

1 个答案:

答案 0 :(得分:0)

试试这个:

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

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