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
Gaurav_NBINGaurav_NBIN 

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: &quot;&quot;
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>. 

 

 

ManjunathManjunath

Hi,

 

Post your apex controller, generated class and vf page.

 

Regards,

Manjunath

Gaurav_NBINGaurav_NBIN

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'};

    }

}

ManjunathManjunath

Hi,

 

Your controller's methods return type should be pagereference.

That should do it.

 

Regards,

Manjunath

ManjunathManjunath

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

Gaurav_NBINGaurav_NBIN

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.

ManjunathManjunath

Hi,

 

Change the return type to pagereference. That will do it.

 

Regards,

Manjunath

Gaurav_NBINGaurav_NBIN

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.

 

ManjunathManjunath

Hi,

Try this

 

public PageReference  hello(){
    try{
     webserviceCom.ReturnHello hello = new webserviceCom.ReturnHello();
     hello.returnHello(); // this value should be saved in a variable. Call the stored value in the vf page.
     return null;

     }
     catch(Exception e)
     {System.debug('ERROR:' + e);}
   }


Regards,

Manjunath

Gaurav_NBINGaurav_NBIN

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 - 

Status

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 - 

04:27:35.049 (49489000)|USER_DEBUG|[6]|DEBUG|-----------------Method calling
04:27:35.049 (49495000)|SYSTEM_METHOD_EXIT|[6]|System.debug(ANY)
04:27:35.049 (49528000)|METHOD_ENTRY|[7]|01p900000026lWl|webserviceCom.ReturnHello.returnHello()
04:27:35.050 (50450000)|CONSTRUCTOR_ENTRY|[18]|01p900000026lWl|<init>()
04:27:35.050 (50490000)|SYSTEM_CONSTRUCTOR_ENTRY|[5]|<init>()
04:27:35.050 (50514000)|SYSTEM_CONSTRUCTOR_EXIT|[5]|<init>()
04:27:35.050 (50535000)|SYSTEM_METHOD_ENTRY|[5]|LIST<String>.add(Object)
04:27:35.050 (50546000)|SYSTEM_METHOD_EXIT|[5]|LIST<String>.add(Object)
04:27:35.050 (50558000)|SYSTEM_METHOD_ENTRY|[5]|LIST<String>.add(Object)
04:27:35.050 (50568000)|SYSTEM_METHOD_EXIT|[5]|LIST<String>.add(Object)
04:27:35.050 (50579000)|SYSTEM_METHOD_ENTRY|[5]|LIST<String>.add(Object)
04:27:35.050 (50588000)|SYSTEM_METHOD_EXIT|[5]|LIST<String>.add(Object)
04:27:35.050 (50602000)|SYSTEM_CONSTRUCTOR_ENTRY|[6]|<init>()
04:27:35.050 (50622000)|SYSTEM_CONSTRUCTOR_EXIT|[6]|<init>()
04:27:35.050 (50631000)|CONSTRUCTOR_EXIT|[18]|01p900000026lWl|<init>()
04:27:35.051 (51650000)|SYSTEM_METHOD_ENTRY|[21]|MAP<String,webserviceCom.returnHelloResponse_element>.put(Object, Object)
04:27:35.051 (51682000)|SYSTEM_METHOD_EXIT|[21]|MAP<String,webserviceCom.returnHelloResponse_element>.put(Object, Object)
04:27:35.051 (51697000)|SYSTEM_CONSTRUCTOR_ENTRY|[22]|<init>()
04:27:35.051 (51713000)|SYSTEM_CONSTRUCTOR_EXIT|[22]|<init>()
04:27:35.051 (51729000)|SYSTEM_METHOD_ENTRY|[22]|LIST<String>.add(Object)
04:27:35.051 (51740000)|SYSTEM_METHOD_EXIT|[22]|LIST<String>.add(Object)
04:27:35.051 (51753000)|SYSTEM_METHOD_ENTRY|[22]|LIST<String>.add(Object)
04:27:35.051 (51762000)|SYSTEM_METHOD_EXIT|[22]|LIST<String>.add(Object)
04:27:35.051 (51772000)|SYSTEM_METHOD_ENTRY|[22]|LIST<String>.add(Object)
04:27:35.051 (51781000)|SYSTEM_METHOD_EXIT|[22]|LIST<String>.add(Object)
04:27:35.051 (51792000)|SYSTEM_METHOD_ENTRY|[22]|LIST<String>.add(Object)
04:27:35.051 (51801000)|SYSTEM_METHOD_EXIT|[22]|LIST<String>.add(Object)
04:27:35.051 (51810000)|SYSTEM_METHOD_ENTRY|[22]|LIST<String>.add(Object)
04:27:35.051 (51819000)|SYSTEM_METHOD_EXIT|[22]|LIST<String>.add(Object)
04:27:35.051 (51830000)|SYSTEM_METHOD_ENTRY|[22]|LIST<String>.add(Object)
04:27:35.051 (51838000)|SYSTEM_METHOD_EXIT|[22]|LIST<String>.add(Object)
04:27:35.051 (51851000)|SYSTEM_METHOD_ENTRY|[22]|LIST<String>.add(Object)
04:27:35.051 (51859000)|SYSTEM_METHOD_EXIT|[22]|LIST<String>.add(Object)
04:27:35.051 (51911000)|SYSTEM_METHOD_ENTRY|[22]|WebServiceCallout.invoke(APEX_OBJECT, APEX_OBJECT, MAP, LIST)
04:27:35.057 (57576000)|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>
04:27:35.057 (57635000)|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 
04:27:35.059 (59075000)|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: &quot;&quot;
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.22
Cache-Control: max-age=259200
Connection: keep-alive


</PRE>
<P>
The following error was encountered:
<UL>
<LI>
<STRONG>
Invalid Request
</STRONG>
</UL>

 

ManjunathManjunath

Hi,

 

I think, problem is where you have hosted your webservice.

 

Regards,

Manjunath

 

Gaurav_NBINGaurav_NBIN

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.

ManjunathManjunath

Hi,

 

Try to host your webservice in static server.

Then redo the whole process(generation of proxy class ..etc)

 

Regards,

Manjunath