Thursday, August 18, 2011

BCS Connection to WCF Web Service

Introduction

I recently needed to connect BCS to some WCF services. The goal was show how I can then use the data out of those WCF services as a data source for FAST. Creating a WCF service and publishing it out through IIS was a pretty simple task. For search you only really need two web methods. First you will need a method that returns a full collection of the dataset which will be used as part of the indexing process. The second method you will need is a get item method that will get the details of a record in the data set.

Issue I ran into

However I ran into a challenge with getting the connection to work initially. When filling in the WCF connection window I would get errors like:

clip_image002

clip_image004

In the Event Logs I had some more detailed errors which really did not help much.

Could not obtain a proxy to WebService for LobSystem 'Default' in App Domain 'ConnectionDomain'. The full exception text is: Metadata contains a reference that cannot be resolved: 'http://demo2010a:8000/SoftwareService/SoftwareService.svc'.. The inner exception text is: <?xml version="1.0" encoding="utf-16"?><Fault xmlns="http://www.w3.org/2003/05/soap-envelope"><Code><Value>Sender</Value><Subcode><Value xmlns:a="http://schemas.xmlsoap.org/ws/2005/02/sc">a:BadContextToken</Value></Subcode></Code><Reason><Text xml:lang="en-US">The message could not be processed. This is most likely because the action 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Get' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.</Text></Reason></Fault>.

Could not obtain a proxy to WebService for LobSystem 'Default' in App Domain 'ConnectionDomain'. The full exception text is: There was an error generating the XML document.. The inner exception text is: The type System.Web.Services.Discovery.DiscoveryDocument was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically..

Resolution

After playing around with the configuration I finally found the following worked. Notice the “mex” extension added to the end of the Service Metadata URL. Once I had that done, just wire up the web methods like you would anything else in BCS.

clip_image005

Now here is another way to do this. Any service that has a wsdl description can be integrated as well. Notice here how I put the wsdl address for the Service Metadata URL.

clip_image006

No comments: