Create and Consume WCF in Sharepoint

来源:互联网 发布:最小生成树kruskal算法 编辑:程序博客网 时间:2024/05/16 19:12

In this case, you needn't create a seperate Web site for the WCF services, the services will share the same web and port number with existing sharepoint site. Because it is a farm solution, once it is deployed, it will be shared in the whole farm.

 

Here are the steps,

 

1. Create a new Sharepoint Empty project "SPFirstWCF".

 

2. Add Reference.

    a.  System.ServiceModel   

         this one is the core assembly for WCF

    b.  Microsoft.SharePoint.Client.ServerRuntime

         This contain the attribute [BasicHttpBindingServiceMetadataExchangeEndpointAttribute] which allows SharePoint to automatically support metadata exchange endpoints, and is the secret sauce that allows us to develop custom WCF services without having to deploy endpoint configuration to the SharePoint web.config.

         This assembly is locating at %Windows%/assembly/GAC_MSIL/Microsoft.SharePoint.Client.ServerRuntime

 

3. Add a SharePoint Mapped Folder to the ISAPI folder, and create an empty text file with the .SVC extension. Note that it is always a good practice to create a sub-folder when deploying your custom code to the SharePoint file system. It helps keep you custom code separate from the original installed files.

 

4. Create WCF service Interface

 

5. Create WCF service class

6.  The assembly will go to GAC after the deployment. You can check its public token and version number

7. Based on above information, modify the svc file

8. Deploy the solution to the sharepoint farm. you can use this link to check whether it is working

   http://localhost:26292/_vti_bin/GSWCF/gswcf.svc/mex the mata data info should be returned.

9. Create a test console project and add the service reference by using that service URL.

Here is the code,

ALL done!!

 

 

 

原创粉丝点击