function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
EvertonSzekeresEvertonSzekeres 

Web service callout failed

Hi !

I have this web service callout and I am getting an error:

Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':html'

29.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
14:17:43.049 (49323664)|EXECUTION_STARTED
14:17:43.049 (49362144)|CODE_UNIT_STARTED|[EXTERNAL]|FutureHandler - state load
14:17:43.056 (56517697)|CODE_UNIT_FINISHED|FutureHandler - state load
14:17:43.059 (59424317)|EXECUTION_FINISHED
14:17:43.085 (85419917)|EXECUTION_STARTED
14:17:43.085 (85435893)|CODE_UNIT_STARTED|[EXTERNAL]|01pU0000000qNO4|SistemaFF.AtualizarFormando
14:17:43.094 (94095634)|METHOD_ENTRY|[1]|01pU0000000qNO4|SistemaFF.SistemaFF()
14:17:43.094 (94239793)|CONSTRUCTOR_ENTRY|[7]|01pU0000000qNO5|<init>()
14:17:43.094 (94329500)|SYSTEM_CONSTRUCTOR_ENTRY|[12]|<init>()
14:17:43.094 (94373142)|SYSTEM_CONSTRUCTOR_EXIT|[12]|<init>()
14:17:43.094 (94389931)|CONSTRUCTOR_EXIT|[7]|01pU0000000qNO5|<init>()
14:17:43.094 (94418088)|SYSTEM_METHOD_ENTRY|[7]|SistemaFF.__sfdc_svcClient(SistemaFFServiceClient.FormandosSoap)
14:17:43.094 (94435159)|SYSTEM_METHOD_EXIT|[7]|SistemaFF.__sfdc_svcClient(SistemaFFServiceClient.FormandosSoap)
14:17:43.094 (94441448)|METHOD_EXIT|[1]|SistemaFF
14:17:43.122 (122242560)|METHOD_ENTRY|[44]|01pU0000000qNO5|SistemaFFServiceClient.FormandosSoap.ProcessaFormando(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)
14:17:43.125 (125985671)|CONSTRUCTOR_ENTRY|[14]|01pU0000000qNO5|<init>()
14:17:43.126 (126044050)|SYSTEM_CONSTRUCTOR_ENTRY|[95]|<init>()
14:17:43.126 (126074313)|SYSTEM_CONSTRUCTOR_EXIT|[95]|<init>()
14:17:43.126 (126106609)|SYSTEM_CONSTRUCTOR_ENTRY|[96]|<init>()
14:17:43.126 (126116607)|SYSTEM_CONSTRUCTOR_EXIT|[96]|<init>()
14:17:43.126 (126129244)|SYSTEM_CONSTRUCTOR_ENTRY|[97]|<init>()
14:17:43.126 (126138255)|SYSTEM_CONSTRUCTOR_EXIT|[97]|<init>()
14:17:43.126 (126149850)|SYSTEM_CONSTRUCTOR_ENTRY|[98]|<init>()
14:17:43.126 (126158519)|SYSTEM_CONSTRUCTOR_EXIT|[98]|<init>()
14:17:43.126 (126171603)|SYSTEM_CONSTRUCTOR_ENTRY|[99]|<init>()
14:17:43.126 (126180204)|SYSTEM_CONSTRUCTOR_EXIT|[99]|<init>()
14:17:43.126 (126191221)|SYSTEM_CONSTRUCTOR_ENTRY|[100]|<init>()
14:17:43.126 (126200556)|SYSTEM_CONSTRUCTOR_EXIT|[100]|<init>()
14:17:43.126 (126211404)|SYSTEM_CONSTRUCTOR_ENTRY|[101]|<init>()
14:17:43.126 (126219887)|SYSTEM_CONSTRUCTOR_EXIT|[101]|<init>()
14:17:43.126 (126230673)|SYSTEM_CONSTRUCTOR_ENTRY|[102]|<init>()
14:17:43.126 (126239090)|SYSTEM_CONSTRUCTOR_EXIT|[102]|<init>()
14:17:43.126 (126250462)|SYSTEM_CONSTRUCTOR_ENTRY|[103]|<init>()
14:17:43.126 (126258893)|SYSTEM_CONSTRUCTOR_EXIT|[103]|<init>()
14:17:43.126 (126270259)|SYSTEM_CONSTRUCTOR_ENTRY|[104]|<init>()
14:17:43.126 (126278590)|SYSTEM_CONSTRUCTOR_EXIT|[104]|<init>()
14:17:43.126 (126289757)|SYSTEM_CONSTRUCTOR_ENTRY|[105]|<init>()
14:17:43.126 (126298102)|SYSTEM_CONSTRUCTOR_EXIT|[105]|<init>()
14:17:43.126 (126309116)|SYSTEM_CONSTRUCTOR_ENTRY|[106]|<init>()
14:17:43.126 (126317575)|SYSTEM_CONSTRUCTOR_EXIT|[106]|<init>()
14:17:43.126 (126328579)|SYSTEM_CONSTRUCTOR_ENTRY|[107]|<init>()
14:17:43.126 (126337075)|SYSTEM_CONSTRUCTOR_EXIT|[107]|<init>()
14:17:43.126 (126347690)|SYSTEM_CONSTRUCTOR_ENTRY|[108]|<init>()
14:17:43.126 (126357144)|SYSTEM_CONSTRUCTOR_EXIT|[108]|<init>()
14:17:43.126 (126368572)|SYSTEM_CONSTRUCTOR_ENTRY|[109]|<init>()
14:17:43.126 (126377130)|SYSTEM_CONSTRUCTOR_EXIT|[109]|<init>()
14:17:43.126 (126388411)|SYSTEM_CONSTRUCTOR_ENTRY|[110]|<init>()
14:17:43.126 (126396649)|SYSTEM_CONSTRUCTOR_EXIT|[110]|<init>()
14:17:43.126 (126408153)|SYSTEM_CONSTRUCTOR_ENTRY|[111]|<init>()
14:17:43.126 (126416692)|SYSTEM_CONSTRUCTOR_EXIT|[111]|<init>()
14:17:43.126 (126427993)|SYSTEM_CONSTRUCTOR_ENTRY|[112]|<init>()
14:17:43.126 (126436267)|SYSTEM_CONSTRUCTOR_EXIT|[112]|<init>()
14:17:43.126 (126447697)|SYSTEM_CONSTRUCTOR_ENTRY|[113]|<init>()
14:17:43.126 (126455994)|SYSTEM_CONSTRUCTOR_EXIT|[113]|<init>()
14:17:43.126 (126467617)|SYSTEM_CONSTRUCTOR_ENTRY|[114]|<init>()
14:17:43.126 (126475980)|SYSTEM_CONSTRUCTOR_EXIT|[114]|<init>()
14:17:43.126 (126487340)|SYSTEM_CONSTRUCTOR_ENTRY|[115]|<init>()
14:17:43.126 (126495767)|SYSTEM_CONSTRUCTOR_EXIT|[115]|<init>()
14:17:43.126 (126506565)|SYSTEM_CONSTRUCTOR_ENTRY|[116]|<init>()
14:17:43.126 (126515158)|SYSTEM_CONSTRUCTOR_EXIT|[116]|<init>()
14:17:43.126 (126526646)|SYSTEM_CONSTRUCTOR_ENTRY|[117]|<init>()
14:17:43.126 (126535136)|SYSTEM_CONSTRUCTOR_EXIT|[117]|<init>()
14:17:43.126 (126546518)|SYSTEM_CONSTRUCTOR_ENTRY|[118]|<init>()
14:17:43.126 (126554861)|SYSTEM_CONSTRUCTOR_EXIT|[118]|<init>()
14:17:43.126 (126565902)|SYSTEM_CONSTRUCTOR_ENTRY|[119]|<init>()
14:17:43.126 (126574501)|SYSTEM_CONSTRUCTOR_EXIT|[119]|<init>()
14:17:43.126 (126587017)|SYSTEM_CONSTRUCTOR_ENTRY|[120]|<init>()
14:17:43.126 (126595488)|SYSTEM_CONSTRUCTOR_EXIT|[120]|<init>()
14:17:43.126 (126606781)|SYSTEM_CONSTRUCTOR_ENTRY|[121]|<init>()
14:17:43.126 (126615373)|SYSTEM_CONSTRUCTOR_EXIT|[121]|<init>()
14:17:43.126 (126626964)|SYSTEM_CONSTRUCTOR_ENTRY|[122]|<init>()
14:17:43.126 (126635444)|SYSTEM_CONSTRUCTOR_EXIT|[122]|<init>()
14:17:43.126 (126646609)|SYSTEM_CONSTRUCTOR_ENTRY|[123]|<init>()
14:17:43.126 (126655094)|SYSTEM_CONSTRUCTOR_EXIT|[123]|<init>()
14:17:43.126 (126666422)|SYSTEM_CONSTRUCTOR_ENTRY|[124]|<init>()
14:17:43.126 (126675060)|SYSTEM_CONSTRUCTOR_EXIT|[124]|<init>()
14:17:43.126 (126686228)|SYSTEM_CONSTRUCTOR_ENTRY|[125]|<init>()
14:17:43.126 (126695493)|SYSTEM_CONSTRUCTOR_EXIT|[125]|<init>()
14:17:43.126 (126705562)|SYSTEM_CONSTRUCTOR_ENTRY|[126]|<init>()
14:17:43.126 (126714203)|SYSTEM_CONSTRUCTOR_EXIT|[126]|<init>()
14:17:43.126 (126746069)|CONSTRUCTOR_EXIT|[14]|01pU0000000qNO5|<init>()
14:17:43.128 (128189200)|SYSTEM_METHOD_ENTRY|[47]|MAP<String,SistemaFFServiceClient.ProcessaFormandoResponse_element>.put(Object, Object)
14:17:43.128 (128223338)|SYSTEM_METHOD_EXIT|[47]|MAP<String,SistemaFFServiceClient.ProcessaFormandoResponse_element>.put(Object, Object)
14:17:43.128 (128233763)|SYSTEM_CONSTRUCTOR_ENTRY|[48]|<init>()
14:17:43.128 (128244620)|SYSTEM_CONSTRUCTOR_EXIT|[48]|<init>()
14:17:43.128 (128370810)|SYSTEM_METHOD_ENTRY|[48]|WebServiceCallout.invoke(APEX_OBJECT, APEX_OBJECT, MAP, LIST)
14:17:43.133 (133441746)|CALLOUT_REQUEST|[48]|ProcessaFormando_element:[Autorizacao=XXX, Autorizacao_type_info=(Autorizacao, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Bairro_xc=XXXX X, Bairro_xc_type_info=(Bairro__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Celular_da_mae_xc=(XX) XXXX-XXXX, Celular_da_mae_xc_type_info=(Celular_da_mae__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Celular_do_pai_xc=null, Celular_do_pai_xc_type_info=(Celular_do_pai__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Cep_xc=XXXX-XXX, Cep_xc_type_info=(Cep__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Cidade_xc=XXX, Cidade_xc_type_info=(Cidade__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Complemento_xc=null, Complemento_xc_type_info=(Complemento__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Data_pedido_AR_xc=null, Data_pedido_AR_xc_type_info=(Data_pedido_AR__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Data_pedido_SA_xc=null, Data_pedido_SA_xc_type_info=(Data_pedido_SA__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Email_alternativo_xc=null, Email_alternativo_xc_type_info=(Email_alternativo__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Empresa_Separacao_xc=null, Empresa_Separacao_xc_type_info=(Empresa_Separacao__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Endereco_xc=XXX XX, Endereco_xc_type_info=(Endereco__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), FirstName=XXXXX, FirstName_type_info=(FirstName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Fotos_Baile_xc=0, Fotos_Baile_xc_type_info=(Fotos_Baile__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Fotos_Colacao_xc=27, Fotos_Colacao_xc_type_info=(Fotos_Colacao__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Fotos_Outros_xc=48, Fotos_Outros_xc_type_info=(Fotos_Outros__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), ID_do_formando_xc=XXX_XXXX_XXXXXX, ID_do_formando_xc_type_info=(ID_do_formando__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), LastName=XXXXX XXXX, LastName_type_info=(LastName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Nome_da_mae_xc=XXXXX XXX, Nome_da_mae_xc_type_info=(Nome_da_mae__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Nome_do_pai_xc=null, Nome_do_pai_xc_type_info=(Nome_do_pai__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Nro_xc=null, Nro_xc_type_info=(Nro__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Panoramicas_xc=0, Panoramicas_xc_type_info=(Panoramicas__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), PersonEmail=crsilva95@yahoo.com.br, PersonEmail_type_info=(PersonEmail, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), PersonHomePhone=(XX) XXXX-XXXX, PersonHomePhone_type_info=(PersonHomePhone, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), PersonMobilePhone=(XX) XXXX-XXXX, PersonMobilePhone_type_info=(PersonMobilePhone, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), PersonOtherPhone=null, PersonOtherPhone_type_info=(PersonOtherPhone, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Situa_o_Avulso_xc=XXXXX XXXX - XX XXXXX, Situa_o_Avulso_xc_type_info=(Situa_o_Avulso__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Telefone_da_mae_xc=null, Telefone_da_mae_xc_type_info=(Telefone_da_mae__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), Telefone_do_pai_xc=null, Telefone_do_pai_xc_type_info=(Telefone_do_pai__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), UF_xc=MG, UF_xc_type_info=(UF__c, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), apex_schema_type_info=(http://xx.xxxxxxx.com.br/, true, false), field_order_type_info=(Autorizacao, ID_do_formando_xc, FirstName, LastName, PersonMobilePhone, PersonEmail, PersonHomePhone, Bairro_xc, Celular_da_mae_xc, Celular_do_pai_xc, ...)]::SFDC_STACK_DEPTH=1 SOAPAction="http://xx.xxxxxxx.com.br/ProcessaFormando" User-Agent=SFDC-Callout/31.0 Accept=text/xml Content-Type=text/xml; charset=UTF-8 
14:17:43.157 (157957558)|EXCEPTION_THROWN|[48]|System.CalloutException: Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':html'
14:17:43.158 (158055274)|SYSTEM_METHOD_EXIT|[48]|WebServiceCallout.invoke(APEX_OBJECT, APEX_OBJECT, MAP, LIST)
14:17:43.158 (158110898)|FATAL_ERROR|System.CalloutException: Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':html'

Class.SistemaFFServiceClient.FormandosSoap.ProcessaFormando: line 48, column 1
Class.SistemaFF.AtualizarFormando: line 44, column 1
14:17:43.158 (158124309)|FATAL_ERROR|System.CalloutException: Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':html'

Class.SistemaFFServiceClient.FormandosSoap.ProcessaFormando: line 48, column 1
Class.SistemaFF.AtualizarFormando: line 44, column 1
14:17:43.381 (158139458)|CUMULATIVE_LIMIT_USAGE
14:17:43.381|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 200
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 60000
  Maximum heap size: 0 out of 12000000
  Number of callouts: 1 out of 10
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 10
  Number of Mobile Apex push calls: 0 out of 10

14:17:43.381|CUMULATIVE_LIMIT_USAGE_END

14:17:43.158 (158163968)|CODE_UNIT_FINISHED|SistemaFF.AtualizarFormando
14:17:43.161 (161667998)|EXECUTION_FINISHED

What I can't understand is that just in sometimes I got the error and in another times works fine.

What should I do?
James LoghryJames Loghry
When I've seen this error, it's likely due to the callout failing for some other reason, and then the service returns an HTML based error message.

The best way to debug this is to construct and make the same request using a tool like soapui (www.soapui.org), and then you should see the actual response from the service.  Hopefully the error message / response will tell you what's wrong with your request.

Best of luck.