Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Dec 2011
    Location
    Italy
    Posts
    43
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Soap xml curl Request return empty response or 1

    Hi guys,
    i'm facing a problem with a web server curl soap call.
    The response to my call is always blank if i set CURLOPT_RETURNTRANSFER true or 1 and otherwise if i set CURLOPT_RETURNTRANSFER to false or 0 the response is always 1

    If i make any error either in header or in soap request the response is always correct.

    I assume my problem is not with the request itself.

    I've been creating soap request either via Dom and with a class i wrote for ebay soap api calls. With the same result.
    I can paste any part of code.

    CURL
    Code:
    	public function sendRequest($glsCall, $requestBody, $gls_lenght)
    	{
    		//build gls headers using variables passed via constructor as well as the gls call to use
    		$headers = $this->buildGlsHeaders($glsCall, $gls_lenght);
    		
    		//initialise a CURL session
    		$connection = curl_init();
    		
    		//set the server we are using 
    		curl_setopt($connection, CURLOPT_URL, 'http://weblabeling.gls-italy.com/IlsWebService.asmx');
    		
    		//Time out
    		curl_setopt($connection, CURLOPT_CONNECTTIMEOUT, 10);
    		curl_setopt($connection, CURLOPT_TIMEOUT, 10);
    		
    		//set it to return the transfer as a string from curl_exec
    		curl_setopt($connection, CURLOPT_RETURNTRANSFER, true);
    		
    		//stop CURL from verifying the peer's certificate
    		curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, false);
    		curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, false);
    		
    		//set method as POST
    		curl_setopt($connection, CURLOPT_POST, true);
    		
    		//set the XML body of the request
    		curl_setopt($connection, CURLOPT_POSTFIELDS, $requestBody);
    		
    		//set the headers using the array of headers
    		curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
            
    		//Testing the connection
    		if(curl_exec($connection) === false)
    		{                
    			$err = 'Curl error: ' . curl_error($connection);
    			curl_close($connection);
    			return $err;
    		}
    		else
    		{
    			//Send the Request
    			$response = curl_exec($connection);
    			
    			//close the connection
    			curl_close($connection); 
    			
    			//return the response
    			return $response;
    		}
    	}
    Headers
    Code:
    	public function buildGlsHeaders($glsCall,$gls_lenght)
    	{
    		$headers = array (			
    			//header soap 1.1
    			"POST /IlsWebService.asmx HTTP/1.1",
    			"Host: weblabeling.gls-italy.com",
    			"Content-Type: text/xml; charset=utf-8",
    			"Content-Length: " . $gls_lenght,
    			"SOAPAction: \"http://weblabeling.gls-italy.com/AddParcel\"",
    		);
    		
    		return $headers;
    	}
    Thanks in advance,
    Fabio
    Last edited by fozzo; 10-30-2012 at 12:11 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Is this $requestBody a valid soap:envelope? If it is, try just setting the soapAction to run instead.
    Any reason why you don't just use the SOAPClient class?

  • #3
    New Coder
    Join Date
    Dec 2011
    Location
    Italy
    Posts
    43
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks for your answer.
    i've been checked xml/soap file on some online checker, it should be fine, the most told so, some other told not (indicating error in ">" of soap:envelope)

    I tried to use soap class as well but the respose from webserver was always bad xml error, so i used my class wich is already tested and working, i'm using for ebay api calls.

    I don't understand why if i take something off from the schema, like a child, i get as response a correct answer with error because of xml format error.

    If the xml looks correct i got no answer and bad request as well (HTTP/1.1 400 Bad Request header)
    Last edited by fozzo; 10-30-2012 at 04:58 PM.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    That's the question though, is the XML valid and correct? It has to match the schema provided by using the request (see here for the schema doc: http://www.soapuser.com/basics3.html). It doesn't matter if your XML is valid, it has to be correct as well and matching that soap envelop schema in order for the server to understand it.

    SOAPClient on the other hand is a matter of giving it a link to the remote wsdl. Then you literally call it if it were a function:
    PHP Code:
    try
    {
        
    $sc = new SOAPClient('http://asite.com/soap.wsdl');
        
    $result $sc->AddParcel($not$sure$if$takes$params);
    }
    catch (
    SOAPException $ex)
    {
        print 
    $ex->getMessage();

    Way easier to use a soap client.

  • #5
    New Coder
    Join Date
    Dec 2011
    Location
    Italy
    Posts
    43
    Thanks
    2
    Thanked 0 Times in 0 Posts
    if i use std class to construct xml
    Code:
    $XMLInfoParcel = new stdClass();
    $XMLInfoParcel->Info->SedeGls = $SedeGls;
    $XMLInfoParcel->Info->CodiceClienteGls = $CodiceClienteGls;
    $XMLInfoParcel->Info->PasswordClienteGls = $PasswordClienteGls;
    $XMLInfoParcel->Info->Parcel = new stdClass();
    $XMLInfoParcel->Info->Parcel->CodiceContrattoGls = $cod_cont;
    $XMLInfoParcel->Info->Parcel->RagioneSociale = $rag_soc;
    $XMLInfoParcel->Info->Parcel->Indirizzo = $delivery_indirizzo;
    $XMLInfoParcel->Info->Parcel->Localita = $delivery_city;
    $XMLInfoParcel->Info->Parcel->Zipcode = $data['delivery_postcode'];
    $XMLInfoParcel->Info->Parcel->Provincia = $data['zone_code'];
    $XMLInfoParcel->Info->Parcel->Bda = '';
    $XMLInfoParcel->Info->Parcel->DataDocumentoTrasporto = '';
    $XMLInfoParcel->Info->Parcel->Colli = '1';
    $XMLInfoParcel->Info->Parcel->Incoterm = '';
    $XMLInfoParcel->Info->Parcel->PesoReale = '1,00';
    $XMLInfoParcel->Info->Parcel->ImportoContrassegno = $imp_cont;
    $XMLInfoParcel->Info->Parcel->NoteSpedizione = $data['customers_telephone'];
    $XMLInfoParcel->Info->Parcel->TipoPorto = 'F';
    $XMLInfoParcel->Info->Parcel->Assicurazione = $***_ins;
    $XMLInfoParcel->Info->Parcel->PesoVolume = '';
    $XMLInfoParcel->Info->Parcel->TipoCollo = $tipo_collo;
    $XMLInfoParcel->Info->Parcel->FrancoAnticipata = '';
    $XMLInfoParcel->Info->Parcel->RiferimentoCliente = '';
    $XMLInfoParcel->Info->Parcel->NoteAggiuntive   = '';
    $XMLInfoParcel->Info->Parcel->CodiceClienteDestinatario = '';
    $XMLInfoParcel->Info->Parcel->Email = '';
    $XMLInfoParcel->Info->Parcel->Cellulare1 = $telefono_1;
    $XMLInfoParcel->Info->Parcel->Cellulare2 = '';
    $XMLInfoParcel->Info->Parcel->ServiziAccessori = '';
    $XMLInfoParcel->Info->Parcel->ModalitaIncasso = $mod_inc;
    it generates an xml but i'm having problems with the first node
    Code:
    <ns1:AddParcel env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"><param0 xsi:type="enc:Struct"><Info
    This param0 have to be changed with XMLInfoParcel for correct structure.

    So when i send out the request with soapClient it gives me xml format error

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You have me confused here; stdclass won't generate an XML structure. That has to be something that you are doing with it.
    What gives you an XML error, the soapclient or the response from the server? You may need to look at their wsdl to verify the structure expected for the parameters as well.

  • #7
    New Coder
    Join Date
    Dec 2011
    Location
    Italy
    Posts
    43
    Thanks
    2
    Thanked 0 Times in 0 Posts
    double post, sorry
    Last edited by fozzo; 10-30-2012 at 06:31 PM.

  • #8
    New Coder
    Join Date
    Dec 2011
    Location
    Italy
    Posts
    43
    Thanks
    2
    Thanked 0 Times in 0 Posts
    forget about stdclass i used because i read on an example in php documentation.

    anyway now i don't understand what is the correct schema. I have some documentation from webservice where i have xml schema and envelope schema, let me post picture:

    what my script generates:



    this is the soap part required



    this is the string part



    It continues and ends with Info closing
    Last edited by fozzo; 10-30-2012 at 06:45 PM.

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Is that last one what the server expects to receive?
    When you try using this as a soapclient, what is the code you are using? If its to be formatted as that XML, what does it look like prior to providing it to the soapclient? Also, you can pull the __getLastRequest() off of the soapclient itself to see what is sent to the soapserver. I believe you need to add the trace to the soapclient to do that, so the second param of the soapclient constructor would simply be given array('trace' => 1') or appended if an array is already available.

  • #10
    New Coder
    Join Date
    Dec 2011
    Location
    Italy
    Posts
    43
    Thanks
    2
    Thanked 0 Times in 0 Posts
    this is getting tricky. Using curl instead of soapClient i made two call for two different services.

    Service A: ListSped works correctly



    Service B: AddParcel doesn't work



    xml is built in the same way from array in each case and so is curl. I still don't get why in service B doesn't work

  • #11
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Looks to me that its fine and its the data that's no good. You'll have to go through the service's documentation to verify exactly what the structure must be for the parameters you are providing.

  • #12
    New Coder
    Join Date
    Dec 2011
    Location
    Italy
    Posts
    43
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Looks to me that its fine and its the data that's no good. You'll have to go through the service's documentation to verify exactly what the structure must be for the parameters you are providing.
    Allright, thanks for your help,i will check tomorrow. I will keep you posted!

  • #13
    New Coder
    Join Date
    Dec 2011
    Location
    Italy
    Posts
    43
    Thanks
    2
    Thanked 0 Times in 0 Posts
    i checked all data against problems.
    All lenghts are correct and < of max allowed.
    All field is alfanumeric / numeric as requested.

    I'm googling this 400 bad request also if xml is correct to see if anyone experienced something like that.

    If you would have any idea about that please just tell me


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •