Monday
Jan312011
SharePoint 2010 WCF HelloWorld Service and InfoPath
Monday, January 31, 2011 at 10:51PM 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
- Create New Blank VS.NET SharePoint Solution “HelloWorldWCF”
- WCF Service has to be a Farm Solution.
- Add New Item, and select WCF Service (CKSDev)
- 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";
}
} - Compile solution and Deploy to server
Verify Service
- The service is deployed to /_vti_bin/HelloWorldWCF/HelloWorldWCFService.svc
- The endpoint is at http://server/_vti_bin/HelloWorldWCF/HelloWorldWCFService.svc/mex
- Browse it with your browser you should see:
Connect Via InfoPath
- Create an External Connection
- Select SOAP Service, use the /mex endpoint
- You may be asked to authenticate with the service
- Select the method
- Cache, and Retrieve when form load as necessary.
- Bind the result of the web service to a textbox
Test in InfoPath
in
code
code 




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?
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
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.
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
Mark, is your form rich client or browser? What doesn't work?
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?
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.
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.