Terry Luschen

Director of Solution Engineering

Salesforce Apex and Windows Communication Foundation (WCF)

Trying to work with Windows Communication Foundation ( WCF ), which can build web services, from Microsoft can be difficult at times. Here are three links which describe some of those difficulties.

1) The first one is pulled from the DeveloperForce boards…

Error Parsing Net 3.0 WCF WSDL From Apex Code

Answer 1… So, WCF splits the wsdl in to different parts and uses imports and such. We (Salesforce) currently don’t support import or include. We (Salesforce) also don’t support any WS-* specs. Because of these two reasons, it’s best just to use the regular .NET asmx approach.

Answer 2… What in particular in WCF are you looking to use that ASMX doesn’t give you?

So we will struggle trying to import a WSDL from WCF since Salesforce APEX does not support import or include items in the WSDL when doing WSDL2Apex.

2) Another technical reason for the struggles with WCF is explained in this article…

Salesforce Net API Integration

Here is the main answer… WCF does not support WSDL defined SOAP headers which (the) Salesforce API uses for carrying session identifier.

3) Here is a third article where somebody ran into a problem integrating with BizTalk which was using WCF…

Experience Of Biztalk and Salesforce.com Integration

Here is the specific point from this article… (Here Biztalk exposed as WS and Apex API consumes it, initially we had exposed it as a WCF Svc and later on found out that somehow the APEX Api does not like WCF so had to step down on Web Service.)

So if you want to use a web service created from a Microsoft based product and you want to use the WSDL2Apex feature then it seems you must generate a traditional .asmx web service.

Here is a nice article that gives some pointers when you see errors when importing your WSDL using WSDL2Apex…

Consuming ASP.NET Web Service

Of course, if you cannot get your WSDL to import, or if you really only need to make one call out of a large WSDL file, then you can always create your XML dynamically in APEX and then use the Http, HttpRequest and HttpResponse Apex objects to make the needed web service call.
I have been able to make a successful call to a WFC web service using the Http, HttpRequest and HttpResponse objects in APEX. I constructed the XML dynamically and then made the following calls on the HttpRequest object.

Http hL = new Http();
HttpRequest reqL = new HttpRequest();
reqL.setTimeout(60000); //This may be too long in some scenarios
reqL.setEndpoint(endPoint); //String Value
reqL.setHeader(‘SOAPAction’, ‘https://my.service.com/connect/IConnect/ActionToTake’);
reqL.setHeader(‘User-Agent’, ‘SFDC-Callout/22.0’);
reqL.setBody(bodyToSend); //Fully constructed XML body
HttpResponse resL = hL.send(reqL);

If all else fails with SOAP, then look to see if there is a REST option.

Here are a couple of the main links for integrating with Salesforce…

Apex Web Services and Callouts
Integrating with the Force.com Platform

Here is another bit of information related to a common error message when doing integrations. I have received this error message before when trying to connect to a web service…

There was an error processing this request. Details: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

This error means that the certificate on web service is not supported by Salesforce APEX. Salesforce supports a limited number of certificate vendors including VeriSign.

I hope this article helps you to move around these roadblocks quickly when you run into them on your integration projects. Happy integrating!

Posted in: Salesforce, Software Development