-1

I am a beginner in Salesforce. I am getting the data from the WCF web Service but I am not able to get data using the Apex class. I will appreciate any kind of help. Thank you in advance.

First, I did this using C# WCF web service and it is working. Now these data, I have to insert in a VF page. So this Apex class code is used for retrieving these data from that WCF web Service. I am getting these data when I directly open this service link in the browser. So I am not able to understand why I am not getting in Apex code and not able to see in that VF page.

Here's the code:

objReq.setEndpoint('http://localhost:46755/DemoService.svc/GetProductsByid');
   objReq.setMethod('GET');
   String bdy = '{id:"10098765"}';
   objReq.setBody(bdy);
            if(!Test.isRunningTest())
            {                
                objResp = objHttp.send(objReq);
                System.debug(objReq.toString());
                if(objResp.getStatusCode() == 200){
                String resBody = objResp.getBody().replaceAll('Currency','CurrencyData'); 
                resBody = resBody.replaceAll('Number','numberData');

                System.debug('  Res  '+((Main_Class) System.JSON.deserialize(resBody, Main_Class.class)).GetProductsByidResult.resultList);

              return ((Main_Class) System.JSON.deserialize(resBody, Main_Class.class)).GetProductsByidResult.resultList;
                }
1
  • What do you mean "not able to get data"? Can you please be more specific? Are you getting any response at all? Some sort of error? Please edit your post with more information so it is possible to help you.
    – Adrian Larson
    Nov 15, 2016 at 15:12

1 Answer 1

3

You need to consider that Salesforce's server's are located out on the Internet and for one of those server's "localhost" would be the server itself not the local to your office machine that you have setup your demo service on at "http://localhost:46755/DemoService.svc". For Salesforce to call in to such a local machine you would have to have your firewall setup to allow access and provide the machine's IP address in the URL.

If you are just working on the Apex side of this, it is much easier to just pick some pre-existing service already available on the Internet and call that.

5
  • I have setup my firewall and am still facing the issue.
    – Max410
    Nov 16, 2016 at 5:56
  • @Max410 Can you try if you are able to access the URL "localhost:46755/DemoService.svc" outside your network.
    – Rajasekhar
    Nov 16, 2016 at 6:26
  • @rajasekhar I tried and I cannot access this url outside my network.
    – Max410
    Nov 16, 2016 at 6:32
  • @Max410 The URL will have to have the static IP address (or name) that corresponds to the access through your firewall not "localhost".
    – Keith C
    Nov 16, 2016 at 11:01
  • @KeithC Ok I got that. Thank you all for your suggestions.
    – Max410
    Nov 16, 2016 at 11:17

Not the answer you're looking for? Browse other questions tagged .