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
krishna59krishna59 

Web service callout failed

Hi All,

 

I am making a webservice call out with the below apex class.

 

//Generated by wsdl2apex

public class washout {
public class request_element {
public washout.notification notification;
private String[] notification_type_info = new String[]{'notification','urn:WashOut','notification','1','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:WashOut','false','false'};
private String[] field_order_type_info = new String[]{'notification'};
}
public class notification_response_element {
public Boolean ack;
private String[] ack_type_info = new String[]{'ack','http://www.w3.org/2001/XMLSchema','boolean','1','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:WashOut','false','false'};
private String[] field_order_type_info = new String[]{'ack'};
}
public class notification {
public washout.sObject_x sObject_x;
private String[] sObject_x_type_info = new String[]{'sObject','urn:WashOut','sObject','1','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:WashOut','false','false'};
private String[] field_order_type_info = new String[]{'sObject_x'};
}
public class sObject_x {
public String id;
public Boolean isDeleted;
public String recordTypeId;
private String[] id_type_info = new String[]{'id','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
private String[] isDeleted_type_info = new String[]{'isDeleted','http://www.w3.org/2001/XMLSchema','boolean','1','1','false'};
private String[] recordTypeId_type_info = new String[]{'recordTypeId','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:WashOut','false','false'};
private String[] field_order_type_info = new String[]{'id','isDeleted','recordTypeId'};
}
public class salesforce_accounts_port {
public String endpoint_x = 'http://hq12.localtunnel.com/salesforce_accounts';
public Map<String,String> inputHttpHeaders_x;
public Map<String,String> outputHttpHeaders_x;
public String clientCertName_x;
public String clientCert_x;
public String clientCertPasswd_x;
public Integer timeout_x;
private String[] ns_map_type_info = new String[]{'urn:WashOut', 'washout'};
public Boolean notifications(washout.notification notification) {
washout.request_element request_x = new washout.request_element();
washout.notification_response_element response_x;
request_x.notification = notification;
Map<String, washout.notification_response_element> response_map_x = new Map<String, washout.notification_response_element>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'notifications',
'urn:WashOut',
'request',
'urn:WashOut',
'notification_response',
'washout.notification_response_element'}
);
response_x = response_map_x.get('response_x');
return response_x.ack;
}
}
}

 

But the response is not in the expected format and it is raising error

 

System.CalloutException: Web service callout failed: Unexpected element. Parser was expecting element 'urn:WashOut:notification_response' but found 'http://schemas.xmlsoap.org/soap/envelope/:notification_response' 

 

When i check logs in developer console the callout response is 

 

<?xml version="1.0" encoding="UTF-8"?>

<Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.xmlsoap.org/soap/envelope/">

<Body>

<notification_response>{"ack"=&gt;"true"}</notification_response>

</Body>

 </Envelope>

 

can any one help me on how to resolve this issue.

 

Thanks,

krishna59.

 

BUSYB0YBUSYB0Y

Test out your webservice using the below link first, make sure its working and you are getting desired results...  and i guess you added the site to remote sites.. correct?

http://www.soapclient.com/soaptest.html

krishna59krishna59

Hi BUSYBOY,

 

I have tested the webservice with the link you provided. Below is the response i got

 

<Body>
<notification_response>{"ack"=>"false"}</notification_response>
</Body>
</Envelope>
 
The "notification_response_element" class in the apex code has "ack" boolean field.
I have doubt with the format ack => false is rendering in the response. Does it have to be in the format of an xml tag like <ack>false</ack>.
 
Is that the reason for the callout to get failed?
 
I am rendering soap response in my webservice as 
render :soap => {:notification_response => {:ack => false}}
 
Thanks,
Sai Krishna.