2016-11-15 60 views
1

我试图使用需要XML响应的SOAP web服务(第三方)将某些表单数据发送到CRM。在Symfony 2中使用NuSoap将数据作为XML发送给第三方WS

我正在使用Symfony 2,实现了noiselabs/NoiselabsNuSOAPBundle来使用NuSoap而不是内置的SOAP客户端,因为我需要HTTP Basic Auth来检索WSDL(看起来它不适用于传统的SOAP客户端)。

然后,我建立了一个服务,它看起来像这样:我应该送这

public function send(Contact $contact) 
{ 
    $xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><lead xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></lead>'); 
    $xml->addChild('firstName', $contact->getName()); 
    $xml->addChild('lastName', $contact->getSurname()); 
    $xml->addChild('companyName', $contact->getCompany()); 
    $xml->addChild('country', $contact->getCountry()); 
    $xml->addChild('city', $contact->getCity()); 
    $xml->addChild('email', $contact->getEmail()); 
    $xml->addChild('phone', $contact->getPhone()); 

    $lead = new \stdClass(); 
    $lead->xml = $xml->asXML(); 

    $url = 'https://my.url.com/CRM?wsdl'; 
    $client = new \nusoap_client($url, true); 
    $client->setCredentials($this->login, $this->password, 'basic'); 
    $client->response_timeout = 5000; 
    return $client->call('SendAndForget', array('param' => $lead->xml)); 
} 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <tem:SendAndForget> 
     <tem:message> 
      <![CDATA[ 
      <?xml version="1.0" encoding="utf-16"?> 
      <lead xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
       <firstName>Name</firstName> 
       <lastName>Surname</lastName> 
       <companyName>Company</companyName> 
       <country>US</country> 
       <city>City</city> 
       <postcode>23231</postcode> 
       <email>[email protected]</email> 
       <phone></phone> 
       </lead> 
      ]]> 
     </tem:message> 
     </tem:SendAndForget> 
    </soapenv:Body> 
</soapenv:Envelope> 

,但我一直有这个错误,我可以找到任何解决方案:

ErrorHandler ->handleError ('8', 'Array to string conversion', 'C:\wamp\www\XXX\vendor\fergusean\nusoap\lib\class.soap_transport_http.php', '971', array('data' => false, 'cErr' => 'Failed to connect to my.url.com port 10443: Timed out', 'err' => 'cURL ERROR: 7: Failed to connect to my.url.com port 10443: Timed out<br>url: https://my.url.com:10443/CRM?wsdl<br>content_type: <br>http_code: 0<br>header_size: 0<br>request_size: 0<br>filetime: 
    -1<br>ssl_verify_result: 0<br>redirect_count: 0<br>total_time: 42.198<br>namelookup_time: 0<br>connect_time: 0<br>pretransfer_time: 0<br>size_upload: 0<br>size_download: 0<br>speed_download: 0<br>speed_upload: 0<br>download_content_length: 
    -1<br>upload_content_length: -1<br>starttransfer_time: 0<br>redirect_time: 0<br>redirect_url: <br>primary_ip: <br>', 'k' => 'certinfo', 'v' => array())) 

任何人都可以看到有什么问题吗?

回答

0

OK,而不是一个解决方案,但解决方法,我在本地导入的WSDL文件,所以我并不需要进行身份验证。使用内置的SoapClient似乎现在就像一个魅力。

public function send($lead) 
{ 
    $client = new \SoapClient($this->file); 
    return $client->SendAndForget($lead->xml); 
} 
0

你可以试试这个:

public function send(Contact $contact) 
{ 

    $params = array(
        "firstName" => $contact->getName(), 
        "lastName" => $contact->getSurname(), 
        ..... 
       ); 

    $url = 'https://my.url.com/CRM?wsdl'; 
    $client = new SoapClient($url); 
    $client->setCredentials($this->login, $this->password, 'basic'); 
    $client->response_timeout = 5000; 
    $client->__soapCall("SendAndForget", $params); 
} 
+0

我得到确切同样的错误,我怕...... – VinZ

+0

如果你想,下午我的WSDL URL,我会看看我能不能帮#2 –

+0

你不能PM :) – VinZ