You need to sign in to do that
Don't have an account?
Neha@Sfdc
unable to provide credentials in apex callouts
Hi all,
i need to invoke a webservice that can be accssed by specifying the credentials.
However i do not find an appropriate way to specify the credentials
in my WSDLToApex class.Below is my Auto generated WSDLToApex class
Or what adjustments do i need to make in the auto generated apex class?
Thanks
i need to invoke a webservice that can be accssed by specifying the credentials.
However i do not find an appropriate way to specify the credentials
in my WSDLToApex class.Below is my Auto generated WSDLToApex class
//Generated by wsdl2apex public class mmmmmSfdcOrdersinbound { public class OrderResponse_element { public String External_Reference_xc; public String SAP_SalesOrder_Id_xc; private String[] External_Reference_xc_type_info = new String[]{'External_Reference__c','urn:mmmmm:sfdc:ordersinbound',null,'0','1','true'}; ..... ........ public class Order_Line_Item_xc { public Integer Line; public String Product_xc; public String Product_Description_xc; public Double Quantity_xc; public String Expected_Delivery_date_xc; public String Sales_Unit_xc; public Boolean FOC_xc; private String[] Line_type_info = new String[]{'Line','urn:mmmmm:sfdc:ordersinbound',null,'0','1','true'}; ...... ...... public class OrderRequest_element { public String CreatedBy; public String LastModifiedBy; public String Owner; public String RecordType; public String Account_Owner_xc; public String Business_Partner_xc; public String Contact_Person_xc; public String Delivery_date_xc; public String Description_xc; public String External_Reference_xc; public Double Net_Value_xc; public String Partner_Id_xc; public String Sales_Organisation_xc; public String Status_xc; public String Visit_xc; public String Wholesaler_xc; public mmmmmSfdcOrdersinbound.Order_Line_Item_xc[] Order_Line_Item_xc; private String[] CreatedBy_type_info = new String[]{'CreatedBy','urn:mmmmm:sfdc:ordersinbound',null,'0','1','true'}; private String[] LastModifiedBy_type_info = new String[]{'LastModifiedBy','urn:mmmmm:sfdc:ordersinbound',null,'0','1','true'}; ......... ......... public class Soap { public String endpoint_x = 'XXXxXXXXXXXX'; 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:mmmmm:sfdc:ordersinbound', 'mmmmmSfdcOrdersinbound'}; public mmmmmSfdcOrdersinbound.OrderResponse_element MIOA_SFDC_to_SAP_Order(String CreatedBy,String LastModifiedBy,String Owner,String RecordType,String Account_Owner_xc,String Business_Partner_xc,String Contact_Person_xc,String Delivery_date_xc,String Description_xc,String External_Reference_xc,Double Net_Value_xc,String Partner_Id_xc,String Sales_Organisation_xc,String Status_xc,String Visit_xc,String Wholesaler_xc,mmmmmSfdcOrdersinbound.Order_Line_Item_xc[] Order_Line_Item_xc) { mmmmmSfdcOrdersinbound.OrderRequest_element request_x = new mmmmmSfdcOrdersinbound.OrderRequest_element(); request_x.CreatedBy = CreatedBy; request_x.LastModifiedBy = LastModifiedBy; request_x.Owner = Owner; .... ...... ....... request_x.Order_Line_Item_xc = Order_Line_Item_xc; mmmmmSfdcOrdersinbound.OrderResponse_element response_x; Map<String, mmmmmSfdcOrdersinbound.OrderResponse_element> response_map_x = new Map<String, mmmmmSfdcOrdersinbound.OrderResponse_element>(); response_map_x.put('response_x', response_x); WebServiceCallout.invoke( this, request_x, response_map_x, new String[]{endpoint_x, '', 'urn:mmmmm:sfdc:ordersinbound', 'OrderRequest', 'urn:mmmmm:sfdc:ordersinbound', 'OrderResponse', 'mmmmmSfdcOrdersinbound.OrderResponse_element'} ); response_x = response_map_x.get('response_x'); return response_x; } } }Can anyone please let me know as to how and where do i specify the credentials?
Or what adjustments do i need to make in the auto generated apex class?
Thanks
1) Try to use Basic instead of BASIC
2) Are you passing all the inputs required for the webserice? try to test the webserice in SOAP UI. in Soap UI also you have to set the credentials.
3) enable the debug for the salesforce user which does the call out and check the debug logs for any other error.
All Answers
I didn't really get as to what you explained.
I am trying to invoke an external webservice that requires credentials.
But i dont understand as to how do i pass in those credentials..when i acess/inoke the above auto generated apex class
mmmmmSfdcOrdersinbound.Soap service = new mmmmmSfdcOrdersinbound.Soap();
service.inputHttpHeaders_x = new Map<String, String>();
service.inputHttpHeaders_x.put('Authorization', 'Basic cGFud2F1dGg6UEBudzQ0MDEh');
cGFud2F1dGg6UEBudzQ0MDEh, replace this with username:password encoded in base 64.
Refer "HTTP Header Support" on this link below.
https://developer.salesforce.com/page/Apex_Web_Services_and_Callouts
http://en.wikipedia.org/wiki/Basic_access_authentication
thanka for your reply,
According to your suggestion my header would be something like this
Is this correct?
00:03:42:737 FATAL_ERROR System.CalloutException: Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':html'
It seems to be redirecting to an error page that renders output in HTML.I assume the error is due to improper authentication.
Can anyone please suggest as to how can i authencate successfully?
createOrder.inputHttpHeaders_x.put('Authorization','Basic <your base 64 of username:password>';
);
1) If you have added the webserice domain name in remote site settings
2) If you have your endpoint correct.
3) If the web service host is allowing outside ip's like salesforce to have access.
check your network team if your websercie can be accessed outside of your company network. the service need be accessed outside of the network and you can provide then salesforce ip ranges.
I beleive mostly your issue with no 3) as given above.
https://help.salesforce.com/apex/HTViewSolution?id=000003652
the endpoint is accessed publicly over the internet.
1.when i open the endpoint on browser,it asks fopr credentials,When i mention the credentials,it displays something with status ok
2.Also now i get an error as
Web service callout failed: Unexpected element. Parser was expecting element 'urn:mmmmmmm:sfdc:ordersinbound:OrderResponse' but found 'http://schemas.xmlsoap.org/soap/envelope/:Body'
The highlighted text shows a slight difference between the previous and the current error
Thanks
1) Try to use Basic instead of BASIC
2) Are you passing all the inputs required for the webserice? try to test the webserice in SOAP UI. in Soap UI also you have to set the credentials.
3) enable the debug for the salesforce user which does the call out and check the debug logs for any other error.
http://www.soapui.org/OAuth/add-authorization.html
1) Once you created the SOAP project using wsdl, click on the request1
2) on the popup window, down below SOAP Request, you will see Auth,Headers, Atttachments etc. it is on the left down corner of the SOPA request window
I tried to invoke the webservvice via SOAP UI tool and it shows an error as
Connection to http://.... refused.
What can e the issue?
i am trying very hard to get through this
i have also provided proper credentials.
Also whenever i open up the endpoint directly via my browser it prompts for credentials.
Thereafter the page displays an message as i had mentioned in the screenshot in my earlier comment.
Is something wrong in my code itself?or its network related problem?
Thanks
When i try to invoke the webservice from apex class it shows up as this:
System.CalloutException: Web service callout failed: Unexpected element. Parser was expecting element 'urn:mmmmmm:sfdc:ordersinbound:OrderResponse' but found 'http://schemas.xmlsoap.org/soap/envelope/:Body'
2) as i said before, check if you are passing all the required inputs
3) is it public webservice or hosted in your network? if it is in your network, then check if it is accessible from Salesforce.
you can access it using your browser does not mean that it is public. you are on the company network while accessing your browser
but sfdc does not call your service from your network.
4) try to test the service in soap UI.
if nothing is working, then submit a new thread so that other people might able to help you.
Now the request is placed successfully in SAP but still an error pops up in sfdc the reason being that they are not sending any response once they send that too will be fixed..
Once again i appreciate all your efforts