You need to sign in to do that
Don't have an account?
Unable to hit SOAP web service due to improper request
Hi All
I am trying to call an external Webservice using APEX.
Here are the steps I have follwed..
1. Created a simple SOAP WS which just return a string.
2. Generated an APEX class using WSDL file.
3. Register the end point in Remote Website
4. Created an APEX controller to call the WS method using callout.
5. Created a APEX Page which has just a button to call the controller.
Issue is, I am can see in the log that it is creating the request XML properly( tested in SOAP UI) but it shows request is not prooper.
Here is my Log, Please suggest me if any step/security measure is missing. Thanks in advance
05:13:34.049 (49868000)|SYSTEM_METHOD_ENTRY|[22]|WebServiceCallout.invoke(APEX_OBJECT, APEX_OBJECT, MAP, LIST) 05:13:34.056 (56853000)|CALLOUT_REQUEST|[22]|<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><env:Header /><env:Body><returnHello xmlns="http://webService.com" /></env:Body></env:Envelope> 05:13:34.056 (56933000)|CALLOUT_REQUEST|[22]|returnHello_element:[apex_schema_type_info=(http://webService.com, true, false), field_order_type_info=()]::SFDC_STACK_DEPTH=1 SOAPAction="" User-Agent=SFDC-Callout/26.0 Accept=text/xml Content-Type=text/xml; charset=UTF-8 05:13:34.058 (58338000)|CALLOUT_RESPONSE|[22]|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <TITLE>ERROR: The requested URL could not be retrieved</TITLE> <STYLE type="text/css"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}PRE{font-family:sans-serif}--></STYLE> </HEAD><BODY> <H1>ERROR</H1> <H2>The requested URL could not be retrieved</H2> <HR noshade size="1px"> <P> While trying to process the request: <PRE> POST /helloCallToWS/services/ReturnHello HTTP/1.0 SFDC_STACK_DEPTH: 1 SOAPAction: "" User-Agent: SFDC-Callout/26.0 Accept: text/xml Content-Type: text/xml; charset=UTF-8 Host: localhost:8080 Content-Length: 300 Via: 1.1 proxy-tyo.net.salesforce.com:8080 (squid) X-Forwarded-For: 10.238.12.21 Cache-Control: max-age=259200 Connection: keep-alive </PRE> <P> The following error was encountered: <UL> <LI> <STRONG> Invalid Request </STRONG> </UL> <P> Some aspect of the HTTP Request is invalid. Possible problems: <UL> <LI>Missing or unknown request method <LI>Missing URL <LI>Missing HTTP Identifier (HTTP/1.0) <LI>Request is too large <LI>Content-Length missing for POST or PUT requests <LI>Illegal character in hostname; underscores are not allowed </UL> <P>Your cache administrator is <A HREF="mailto:support@salesforce.com">support@salesforce.com</A>.
Hi,
Post your apex controller, generated class and vf page.
Regards,
Manjunath
Controller:-
global class WSController{
public void hello(){
try{
webserviceCom.ReturnHello hello = new webserviceCom.ReturnHello();
hello.returnHello();
}
catch(Exception e)
{System.debug('ERROR:' + e);}
}
}
VF page:-
<apex:page standardStylesheets="false" sidebar="false" showHeader="false" extensions="WSController"
controller="WSController">
<h1>WelCome to CallOut</h1>
<apex:form >
<apex:commandButton id="testCallOut_" value="InvokeWebService" action="{!hello}"/>
</apex:form>
</apex:page>
APEX Generated class:-
//Generated by wsdl2apex
public class webserviceCom {
public class returnHello_element {
private String[] apex_schema_type_info = new String[]{'http://webService.com','true','false'};
private String[] field_order_type_info = new String[]{};
}
public class ReturnHello {
public String endpoint_x = 'http://localhost:8080/helloCallToWS/services/ReturnHello';
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[]{'http://webService.com', 'webserviceCom'};
public String returnHello() {
webserviceCom.returnHello_element request_x = new webserviceCom.returnHello_element();
webserviceCom.returnHelloResponse_element response_x;
Map<String, webserviceCom.returnHelloResponse_element> response_map_x = new Map<String, webserviceCom.returnHelloResponse_element>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'',
'http://webService.com',
'returnHello',
'http://webService.com',
'returnHelloResponse',
'webserviceCom.returnHelloResponse_element'}
);
response_x = response_map_x.get('response_x');
return response_x.returnHelloReturn;
}
}
public class returnHelloResponse_element {
public String returnHelloReturn;
private String[] returnHelloReturn_type_info = new String[]{'returnHelloReturn','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
private String[] apex_schema_type_info = new String[]{'http://webService.com','true','false'};
private String[] field_order_type_info = new String[]{'returnHelloReturn'};
}
}
Hi,
Your controller's methods return type should be pagereference.
That should do it.
Regards,
Manjunath
Hi,
hello.returnHello() method gives you a string value, That should be saved in your controller variable. Call this variable in VF page to display the result.
Regards,
Manjunath
Thank you so much for the reply Manjunath.
I just want to know that printing on VF page is another part, first I should be able to get the proper response in the pog file.
If it hit the WS properly then there must be valid response in log like a valid reqest.
Please correct me if i m wrong.
Hi,
Change the return type to pagereference. That will do it.
Regards,
Manjunath
My changes are
try{
webserviceCom.ReturnHello hello = new webserviceCom.ReturnHello();
PageReference pageRef = hello.returnHello();
return pageRef;
}
Its not compiling, as the return is String and I am trying to save in pageRef. I tried typecasting as well, but no use. I can not change the anything in hello.returnHello(), please suggest me.
Hi,
Try this
Regards,
Manjunath
Thank you so much Manjunath.
But I am still getting some problem...Please help.
I made the changes in controller
public PageReference hello(){
webserviceCom.ReturnHello hello = new webserviceCom.ReturnHello();
system.debug('-----------------Method calling');
hello.returnHello(); // this value should be saved in a variable. Call the stored value in the vf page.
system.debug('-----------------Method called');
return null;
}
First debug is printed but not the second one.
Error -
Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':HTML'
Here is the log for your ref -
Hi,
I think, problem is where you have hosted your webservice.
Regards,
Manjunath
I have deployed WS on Tomcat and able to access the same using SOAP UI. Even I can hit the response of the request generated by APEX class.
Do u still think the problem is with hosting???
Please do the needful.
Hi,
Try to host your webservice in static server.
Then redo the whole process(generation of proxy class ..etc)
Regards,
Manjunath