tomsihap
tomsihap

Reputation: 1769

Error when using SoapClient but not when using the web browser

Using the Chronopost Web Services.

When using this post HTTP request in a web browser (account number and password are hidden there, so you can't test yourself unless you have a Chronopost ID) :

https://ws.chronopost.fr/shipping-cxf/ShippingServiceWS/shippingWithReservationAndESDWithRefClientPC?subAccount=000&accountNumber=ACCOUNT_NUMBER&password=PASSWORD&shipperCivility=E&shipperName=DELBET&shipperName2=RICHARD&shipperAdress1=1%20rue%20des%20accents&shipperZipCode=28500&shipperCity=Ste%20Gemme%20Moronval&shipperCountry=FR&shipperCountryName=France&shipperContactName=Richard%20Delbet&[email protected]&shipperPhone=0123456789&shipperMobilePhone=0601020304&recipientCivility=E&recipientName=MALKA&recipientName2=DAVID&recipientAdress1=1%20rue%20des%20essais&recipientZipCode=75001&recipientCity=Paris&recipientCountry=FR&recipientCountryName=France&recipientContactName=David%20Malka&[email protected]&recipientPhone=0222426789&recipientMobilePhone=0622220304&shipperRef=CMD1&recipientRef=ART1&productCode=01&shipDate=27/07/2010%2010:00:00&shipHour=10&weight=2&service=0&objectType=MAR&modeRetour=1&mode=PDF

I have a valid response with all the correct datas.

When using SoapClient with exactly the same parameters :

$client = new \SoapClient("http://ws.chronopost.fr/shipping-cxf/ShippingServiceWS?wsdl");
    $data = [
      'subAccount' => '000',
      'accountNumber' => ACCOUNT_NUMBER,
      'password' => PASSWORD,
      'shipperCivility' => 'E',
      'shipperName' => 'DELBET',
      'shipperName2' => 'RICHARD',
      'shipperAdress1' => '1%20rue%20des%20accents',
      'shipperZipCode' => '28500',
      'shipperCity' => 'Ste%20Gemme%20Moronval',
      'shipperCountry' => 'FR',
      'shipperCountryName' => 'France',
      'shipperContactName' => 'Richard%20Delbet',
      'shipperEmail' => '[email protected]',
      'shipperPhone' => '0123456789',
      'shipperMobilePhone' => '0601020304',
      'recipientCivility' => 'E',
      'recipientName' => 'MALKA',
      'recipientName2' => 'DAVID',
      'recipientAdress1' => '1%20rue%20des%20essais',
      'recipientZipCode' => '75001',
      'recipientCity' => 'Paris',
      'recipientCountry' => 'FR',
      'recipientCountryName' => 'France',
      'recipientContactName' => 'David%20Malka',
      'recipientEmail' => '[email protected]',
      'recipientPhone' => '0222426789',
      'recipientMobilePhone' => '0622220304',
      'shipperRef' => 'CMD1',
      'recipientRef' => 'ART1',
      'productCode' => '01',
      'shipDate' => '27/07/2010%2010:00:00',
      'shipHour' => '10',
      'weight' => '2',
      'service' => '0',
      'objectType' => 'MAR',
      'modeRetour' => '1',
      'mode' => 'PDF',
    ];
    $response = $client->__soapCall("shippingWithReservationAndESDWithRefClientPC", array($data));

I have an error returned :

object(stdClass)#531 (1) { ["return"]=> object(stdClass)#537 (2) { ["errorCode"]=> int(1) ["errorMessage"]=> string(3112) " fr.chronopost.soap.shipping.exception.ValidateException at fr.chronopost.soap.shipping.util.PopulateUtils.populateSkybill(PopulateUtils.java:355) at fr.chronopost.soap.shipping.cxf.ShippingServiceWS.shippingWithReservationAndESDWithRefClientPC(ShippingServiceWS.java:615) at sun.reflect.GeneratedMethodAccessor1258.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:136) at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:82) at org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:54) at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:68) at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:56) at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37) at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:92) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220) at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:78) at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:92) at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:285) at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:168) at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:175) at org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:153) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190) at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291) at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:776) at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:705) at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:898) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690) at java.lang.Thread.run(Thread.java:744) " } }

Unfortunately, the error code "1" is described in the documentation as "system error".

One proabably can't help me directly about the Chronopost Web Services, but maybe I'm missing something into the PHP SoapClient object.

Why do I have a correct response when using a web browser and some kind of ValidateException error when using SoapClient ?

Upvotes: 4

Views: 407

Answers (1)

Kris Peeling
Kris Peeling

Reputation: 1025

When making a SOAP call, you don't need to include URL encoded data strings. Php soapclient encodes the data into XML automatically. So the problem is most likely the validation the service is performing on your data, and it's choking on the % characters. Try changing

'shipDate' => '27/07/2010%2010:00:00'

to

'shipDate' => '27/07/2010 10:00:00'

Upvotes: 2

Related Questions