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
gbu.varungbu.varun 

SOAP WebServiceCallout.invoke

Hi,

 

I am invoking a php web service though apex code. I am able to invoke my php web service by php client but I am not able to invoke it through apex.  I am setting header for authentication as :

 

        HttpRequest req = new HttpRequest();
        req.setEndpoint('http://serverurl/file.php?wsdl');
        req.setMethod('GET');
        Blob headerValue = Blob.valueOf(username + ':' + password);
        String authorizationHeader = 'Basic '+ EncodingUtil.base64Encode(headerValue);
        req.setHeader('Authorization', authorizationHeader);
        req.setHeader('Content-Type', 'application/soap+xml');

 

I am able to get  soap (wsdl) by "System.debug(res.getBody()); " command but   I am getting following error "System.CalloutException: Web service callout failed:"   

My webservice.invoke method is as:

            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://test-uri/soap/export/getUsers',
              'http://test-uri/soap/export/',
              'getUsers',
              'http://test-uri/soap/export/',
              'getUsersResponse',
              'testUriSoapExport.getUsersResponse_element'}

            );

 

Is this error due to authentication ?  How can I resolve it ?

 

Thanks,

Varun

 

Best Answer chosen by Admin (Salesforce Developers) 
gbu.varungbu.varun

Hi LVS,

 

I have solved this problem myself. Problem was due to Http Header. I set the credentials in header and solve the issue.

Thanks for reply.

 

Thanks,

Varun

All Answers

LVSLVS

Can't say. It all depends on your web service. Can you look up the documentation for the web service and see if it mentions any response for unauthenticated user, invalid input etc?

 

Some web services fail gracefully - they give a proper HTTP 200 response but add information in the response (SOAP/XML/JSON/anything) that there was something wrong. Other, poorly implemented, web services just fail with an error causing your calling method to fail too.

 

What is the output of your .getBody() call? Or is that where you are getting your exception. The problem mostly might not be in the class generated from WSDL except in some special cases...

gbu.varungbu.varun

Hi LVS,

 

I have solved this problem myself. Problem was due to Http Header. I set the credentials in header and solve the issue.

Thanks for reply.

 

Thanks,

Varun

This was selected as the best answer