« InfoPath 2010 COM Add-ins not available in Form Design | Main | SharePoint and Reporting Services Integration, the good, the bad, and the ugly »
Monday
Jan312011

SharePoint 2010 WCF HelloWorld Service and  InfoPath

Was looking for a quick tutorial for creating a Custom WCF Service for SharePoint 2010.  For some reason couldn’t find one, so I sat down and try it out and decide to write out a few simple steps.

Use CKSDev

http://cksdev.codeplex.com/ version 1.2 included new Visual Studio Item templates for creating WCF services and makes this whole process a breeze.  Thanks to Charlie Holland’s hardwork.

 

Build Solution

  1. Create New Blank VS.NET SharePoint Solution “HelloWorldWCF”
  2. WCF Service has to be a Farm Solution.
  3. Add New Item, and select WCF Service (CKSDev)image
  4. The created Service includes a stub method that returns a string.

    [BasicHttpBindingServiceMetadataExchangeEndpoint]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class HelloWorldWCFService : IHelloWorldWCFService
    {
        // To test this service, use the Visual Studio WCF Test client
        // set the endpoint to http://<Your server name>/_vti_bin/HelloWorldWCF/HelloWorldWCFService.svc/mex
        public string HelloWorld()
        {
            return "Hello World from WCF and SharePoint 2010";
        }
    }
  5. Compile solution and Deploy to server

Verify Service

  1. The service is deployed to /_vti_bin/HelloWorldWCF/HelloWorldWCFService.svc
  2. The endpoint is at http://server/_vti_bin/HelloWorldWCF/HelloWorldWCFService.svc/mex
  3. Browse it with your browser you should see:

image

 

Connect Via InfoPath

  1. Create an External Connection
  2. Select SOAP Service, use the /mex endpoint
  3. You may be asked to authenticate with the service
  4. Select the method

    image
  5. Cache, and Retrieve when form load as necessary.

    image
  6. Bind the result of the web service to a textbox

    image

 

Test in InfoPath

  1. Preview the InfoPath form

    image

Reader Comments (8)

Glad I came across this post. Now, I should be able to pull Oracle data to populate my Infopath combo box. I just need to figure out how to filter the infopath combo box "OnEntry". The filter data -> existing filters -> beginswith functionality does not seem to work properly. Any ideas?

April 6, 2011 | Unregistered CommenterMark

I can view the service in a browser, however when trying to setup the data connection in InfoPath, I get the following error:


WSDLReader:Could not find '/definitions/service' inside the '' namespace of the wsdl file. The parameter is incorrect.
- WSDLReader:Analyzing the WSDL file failed. The parameter is incorrect.

Any ideas?

Thanks

July 12, 2011 | Unregistered CommenterR

R

Use fully qualified name - FQDN of your server within the WCF service url.

It will be present in <soap:address location=" of your service WSDL.

eg. instead of http://atriumsp/_vti_bin/ServiceDynamic/ServiceDynamic.svc/MEX?wsdl USE

http://atriumsp.atrium.com/_vti_bin/ServiceDynamic/ServiceDynamic.svc/MEX?wsdl

where atrium.com is my domain.

August 24, 2011 | Unregistered CommenterHimani

Also, use the WCF test client to make sure it's running and call-able. This should be hiding in your VS.NET Common7/IDE folder. (32bit - so under Program Files x86).

http://msdn.microsoft.com/en-us/library/bb552364.aspx

September 6, 2011 | Registered CommenterJohnLiu.NET

Mark, is your form rich client or browser? What doesn't work?

September 6, 2011 | Registered CommenterJohnLiu.NET

Thanks for this post, John. I hadn't looked at CKS project in some time so your post was very helpful.

However, the only twist I have is I need this service to work over SSL. Over a regular connection this solution works like a breeze, but over SSL I get the following error in the form: "You do not have permissions to access a Web service that provides data required for this form to function correctly."

Being a WCF noob, I see now there will probably be additional configuration required... I just haven't figured out what that will be. Any suggestions?

September 13, 2011 | Unregistered CommenterGDev

Just as a follow-up, it appears that this is an issue with certs recognized by the farm. In my dev environment, I was able to add the cert in Central Admin > Security > General Security > Manage Trust and the WCF service can be called by the form now.

As a general reference, see here: http://msdn.microsoft.com/en-us/library/gg318614.aspx.

September 14, 2011 | Unregistered CommenterGDev

Thank you so much for popping back and following it up. I had seen your comment but didn't have a https setup handy to test it out. Glad it was solved for you.

September 16, 2011 | Registered CommenterJohnLiu.NET

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>