SharePoint 2010 Hosting WCF Services

baasopchoppyΑσφάλεια

5 Νοε 2013 (πριν από 3 χρόνια και 7 μήνες)

360 εμφανίσεις








SharePoint 2010 Hosting WCF Services
Sample Instructions



Introduction

All of the sample code was built on Visual Studio 2010
RTM
, targeting the .Net Framework v3.5.
All
projects will have to be compiled and deployed in your environment.
There are
three

projects that need
to be deployed to IIS and configured properly

and
two

that can be deployed to SharePoint to add user
account management

and tenant quota management

to Tenant Administration
. These
projects
are
:



Microsoft.Hosting.SharePoin
t2010.Services

project (WCF)

o

requires SQL Server 2008 Express to be installed on the server



Microsoft.Hosting.Us
erAccount.Service project (WCF)



SharePointWebControlPanel

project (ASP.NET
)




Microsoft.Hosting.SharePoint2010.UserAccountsWebParts

project (Shar
ePoint)

o

Can only be compiled on a machine that has SharePoint 2010 installed



Microsoft.Hosting.SharePoint2010.

TenantAdmin project (SharePoint)

o

Can only be compiled on a machine that has SharePoint 2010 installed

This code is focused around the multi
-
tenan
t aspects of SharePoint 2010 and includes multi
-
tenant farm
setup, tenant provisioning, and tenant management.

Setting up Windows PowerShell Remoting

The WCF services use Windows PowerShell remoting to access the SharePoint farm server. SharePoint
PowerShe
ll remoting only works with the Credential Security Support Provider (CredSSP) and needs to
be setup on both the server, i.e. the machine that will be connected to, and the client, the machine that
will issue the remoted script.

Use the following command
s

to setup
remoting and
CredSSP

access

on the farm server:

Enable
-
PSRemoting

Enable
-
WSManCredSSP

-
Role server


Use the following command to setup
remoting and
CredSSP on the IIS server:

Enable
-
PSRemoting

Enable
-
WSManCredSSP

-
Role client
-
DelegateComputer
<
server name>


The <server name> parameter should be the name of the SharePoint farm server.

If you are running
everything on one server, both the server and client commands need to be run as the WCF services
always use Windows PowerShell remoting.

Some cmdlets use a lot of memory and can cause out of memory exceptions in remoted scripts. To
increase the size of memory allocated to a remoted session, use the following command on the farm
server:

Set
-
Item

WSMan:
\
localhost
\
Shell
\
MaxMemoryPerShellMB 100
0

AD Group Creation

Create an AD group that can be used to allow access to the services, i.e. contoso
\
hosting services users.
Add the SharePoint web application service account and any other accounts that need to access any of
the services that are in the
sample.

Microsoft.Hosting.SharePoint2010.Services

Make sure you have installed Microsoft SQL Server 2008 Express on the server where this will be
deployed.
Build the solution and publish the project to an IIS server.
The identity of the application pool
fo
r this application should map to the SharePoint Farm service account. Use IIS manager

to promote this
directory to an application and

assign it to an application pool with the proper credentials
.

Change the value of the appSettings
DomainSecurityGroup

to t
he group created above.


<appSettings>


<add key="DomainSecurityGroup" value="
Contoso
\
Hosting Services Users
"/>


</appSettings>



In the published folder, open the web.config file for editing.

Find the Microsoft.Hosting section and edit
the following:


<Microsoft.Hosting>



<PowerShell
userName="
contoso
\
moss_svc
" password="
pass@word1
"
scri
ptPath="
C:
\
Code
\
Release
\
Microsoft.Hosting.SharePoint2010
\
Microsoft.Hosting.SharePoint2010.
Services
\
Scripts
\
">


<PowerShellScripts>


Change the
username

and
password

for the account that will issue remote PowerShell scripts.
Change
the
scriptPath

attribute (highlighted in yellow) to the published path of the service, leaving
\
Scripts
\

on
the end.

Microsoft.Hosting.UserAccount.Services

Build the solution and p
ublish the project to an IIS server. The identity of the application pool for this
application should map to the SharePoint Farm service account. Use IIS manager to promote this
directory to an application and assign it to an application pool with the prop
er credentials.

In the published folder, open the web.config file for editing. Find the Microsoft.Hosting section and edit
the following:


<appSettings>


<add key="DomainSecurityGroup" value="
Contoso
\
Hosting Services Users
"/>


</appSettings>



<conne
ctionStrings>


<remove name="ADConnectionString"/>


<add name="ADConnectionString" connectionString="
LDAP://2k8
-
01/DC=Contoso,DC=COM
"/>


</connectionStrings>


Change the
DomainSecurityGroup

value to the AD group already created. Change the
ADConnect
ionString

to map to the proper domain controller.

SharePointWebControlPanel

Edit the Web.Sitemap file and change the reporting links to point to your Central Administration site.

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap
-
File
-
1.0" >


<
siteMapNode url="~/Default.aspx" title="Home" description="">


<siteMapNode url="" title="Provision" description="" >


<siteMapNode url="~/Pages/ProvisionNewTenant.aspx" title="New Tenant" description=""
/>


<siteMapNode url="~/Pages/N
ewFeaturePack.aspx" title="New Feature Pack" description=""
/>


<siteMapNode url="~/Pages/FarmTenantServices.aspx" title="Farm Tenant Services"
description="" />


</siteMapNode>


<siteMapNode url="" title="Query" description="" >


<siteMapNode url="~/Pages/GetFeaturePacks.aspx" title="Get Feature Packs"
description="" />


</siteMapNode>


<siteMapNode url="" title="Manage" description="" >


<siteMapNode url="~/Pages/GetTenants.aspx" title="Tenants" description="" />


</siteMapNode>


<siteMapNode url="" title="Reporting" description="" >


<siteMapNode url="
http://2k8
-
04:33372
/AdminReports" title="Administration Reports"
description="" />


<siteMapNode url="
http://2k8
-
04:33372
/_layouts/WebAnal
ytics/WebAppSelection.aspx?t=WebApplicationSelectionReport&amp;l=wa"
title="Web Analytics Reports" description="" />


</siteMapNode>


</siteMapNode>

</siteMap>


Build the solution and publish the project to an IIS server.

Use IIS manager to promot
e this directory to
an application.

In the published folder, open the web.config file for editing. Find the
system.serviceModel section and inside that section the client section:



<client>




<endpoint
address="
http://localhost:8080/Microsoft.Hosting.Sha
rePoint2010.Services
/SharePointManagementS
ervice.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IManagementService"
contract="ManagementServices.IManagementService" name="WSHttpBinding_IManagementService">




</endpoint>




<endpoint bind
ing="customBinding"
bindingConfiguration="WebHttpBinding_IManagementService"
contract="ManagementServices.IManagementService" name="WebHttpBinding_IManagementService"/>




<endpoint
address="
http://localhost:8080/Microsoft.Hosting.SharePoint2010.Services
/S
harePointProvisionin
gService.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IProvisioningService"
contract="ProvisioningServices.IProvisioningService"
name="WSHttpBinding_IProvisioningService">




</endpoint>




<endpoint binding="customB
inding"
bindingConfiguration="WebHttpBinding_IProvisioningService"
contract="ProvisioningServices.IProvisioningService"
name="WebHttpBinding_IProvisioningService"/>




<endpoint
address="
http://localhost:8080/Microsoft.Hosting.SharePoint2010.Services
/Share
PointQueryServic
e.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IQueryService"
contract="QueryServices.IQueryService" name="WSHttpBinding_IQueryService">




</endpoint>




<endpoint binding="customBinding"
bindingConfiguration="WebHttpBi
nding_IQueryService" contract="QueryServices.IQueryService"
name="WebHttpBinding_IQueryService"/>



</client>


</system.serviceModel>


Edit the address attributes to point to the virtual directory of the published WCF services. Find the
appSettings section

and edit the following:


<appSettings>



<add key="FarmServer" value="
2k8
-
04
"/>


</appSettings>


Change the value of the
FarmServer

key to a SharePoint server you want to manage.

Microsoft.Hosting.SharePoint2010.UserAccountsWebParts

This project can only be compiled on a machine that has SharePoint 2010 installed. Build and deploy.
Add the following to the SharePoint Web Application web.config’s appSettings setti
ng
s, editing the
ManagementS
erver

value
:


<add key="ManagementServer"
value="
e14
-
sp05
" />


Add the following to the SharePoint Web Application web.config’s system.serviceModel node, editing
the highlighted portions:


<bindings>


<customBinding>


<binding name="WebHttpBinding_IUserAccountProvi
sioningService">


<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"


messageVersion="Soap12" writeEncoding="utf
-
8">


<readerQuotas maxDepth="32" maxStringContentLength="8192"
ma
xArrayLength="16384"


maxBytesPerRead="4096" maxNameTableCharCount="16384" />


</textMessageEncoding>


</binding>


<binding name="WebHttpBinding_IUserAccountManagementService">



<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"


messageVersion="Soap12" writeEncoding="utf
-
8">


<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384"


maxBytesPerRead="4096" maxNameTableCharCount="16384" />


</textMessageEncoding>


</binding>


<binding name="WebHttpBinding_IUserAccountQueryService">


<
textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"


messageVersion="Soap12" writeEncoding="utf
-
8">


<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384"



maxBytesPerRead="4096" maxNameTableCharCount="16384" />


</textMessageEncoding>


</binding>


<binding name="WebHttpBinding_IManagementService">


<textMessageEncoding maxReadPool
Size="64" maxWritePoolSize="16"


messageVersion="Soap12" writeEncoding="utf
-
8">


<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384"


maxBytesPerRead="409
6" maxNameTableCharCount="16384" />


</textMessageEncoding>


</binding>


</customBinding>


<wsHttpBinding>


<binding name="WSHttpBinding_IUserAccountProvisioningService"



closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"


sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false"


hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="52428
8"


maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf
-
8"


useDefaultWebProxy="true" allowCookies="false">


<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLeng
th="16384"


maxBytesPerRead="4096" maxNameTableCharCount="16384" />


<reliableSession ordered="true" inactivityTimeout="00:10:00"


enabled="false" />


<security mode="Messa
ge">


<transport clientCredentialType="Windows" proxyCredentialType="None"


realm="" />


<message clientCredentialType="Windows"
negotiateServiceCredential="true"


algorithmSuite="Default" />


</security>


</binding>


<binding name="WSHttpBinding_IUserAccountManagementService"
closeTimeout="00:01:00"


openTimeout="00:01:00
" receiveTimeout="00:10:00" sendTimeout="00:01:00"


bypassProxyOnLocal="false" transactionFlow="false"
hostNameComparisonMode="StrongWildcard"


maxBufferPoolSize="524288" maxReceivedMessageSize="65536"



messageEncoding="Text" textEncoding="utf
-
8" useDefaultWebProxy="true"


allowCookies="false">


<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384"


maxBytesPerRead
="4096" maxNameTableCharCount="16384" />


<reliableSession ordered="true" inactivityTimeout="00:10:00"


enabled="false" />


<security mode="Message">


<transport clientCred
entialType="Windows" proxyCredentialType="None"


realm="" />


<message clientCredentialType="Windows"
negotiateServiceCredential="true"


algorithmSuite="Default" />



</security>


</binding>


<binding name="WSHttpBinding_IUserAccountQueryService" closeTimeout="00:01:00"


openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"


bypa
ssProxyOnLocal="false" transactionFlow="false"
hostNameComparisonMode="StrongWildcard"


maxBufferPoolSize="524288" maxReceivedMessageSize="65536"


messageEncoding="Text" textEncoding="utf
-
8" useDefaultWebProxy="true"



allowCookies="false">


<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384"


maxBytesPerRead="4096" maxNameTableCharCount="16384" />


<reliableSessi
on ordered="true" inactivityTimeout="00:10:00"


enabled="false" />


<security mode="Message">


<transport clientCredentialType="Windows" proxyCredentialType="None"


realm="" />


<message clientCredentialType="Windows"
negotiateServiceCredential="true"


algorithmSuite="Default" />


</security>


</binding>



<binding name="WSHttpBinding_IManagementService" closeTimeout="00:01:00"


openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"


bypassProxyOnLocal="false" transactionFlow="false"
hostNam
eComparisonMode="StrongWildcard"


maxBufferPoolSize="524288" maxReceivedMessageSize="65536"


messageEncoding="Text" textEncoding="utf
-
8" useDefaultWebProxy="true"


allowCookies="false">



<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384"


maxBytesPerRead="4096" maxNameTableCharCount="16384" />


<reliableSession ordered="true" inactivityTimeout="00:10:00"



enabled="false" />


<security mode="Message">


<transport clientCredentialType="Windows" proxyCredentialType="None"


realm="" />


<message clientCr
edentialType="Windows"
negotiateServiceCredential="true"


algorithmSuite="Default" />


</security>


</binding>


<binding name="WSHttpBinding_IQueryService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding
="utf
-
8" useDefaultWebProxy="true" allowCookies="false">


<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />


<reliableSession order
ed="true" inactivityTimeout="00:10:00"
enabled="false" />


<security mode="Message">


<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />


<
message clientCredentialType="Windows"
negotiateServiceCredential="true" algorithmSuite="Default" />


</security>


</binding>


</wsHttpBinding>


</bindings>


<client>


<endpoint address="
ht
tp://e14
-
sp05.contoso.com:8080/HostingServices
/UserAccountProvisioningService.svc"


binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IUserAccountProvisioningService"


contract="UserAccountProvision.IUserAccountProvi
sioningService"


name="WSHttpBinding_IUserAccountProvisioningService">


<identity>


<servicePrincipalName value="
H
OST
/E14
-
SP05.contoso.com
" />


</identity>


</endpoint>


<endpoint binding="customBinding"
bindingConfiguration="WebHttpBinding_IUserAccountProvisioningService"


contract="UserAccountProvision.IUserAccountProvisioningService"


name="WebHttpBinding_IUserAccountProvisioningService" />


<endpoint address="
http://e14
-
sp05.contoso.com:8080/HostingServices
/UserAccountQueryService.svc"


binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IUserAccountQueryService"


contract="UserAccountQuery.I
UserAccountQueryService"
name="WSHttpBinding_IUserAccountQueryService">


<identity>


<servicePrincipalName value="
HOST/E14
-
SP05.contoso.com
" />


</identity>


</endpoint>


<endpoint bind
ing="customBinding"
bindingConfiguration="WebHttpBinding_IUserAccountQueryService"


contract="UserAccountQuery.IUserAccountQueryService"
name="WebHttpBinding_IUserAccountQueryService" />


<endpoint address="
http://e14
-
sp05.contoso.com:8080/HostingServices
/UserAccountManagementService.svc"


binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IUserAccountManagementService"


contract="UserAccountManage.IUserAccountManagement
Service"


name="WSHttpBinding_IUserAccountManagementService">


<identity>


<servicePrincipalName value="
HOST/E14
-
SP05.contoso.com
" />


</identity>


</endpoint>


<endpoint

binding="customBinding"
bindingConfiguration="WebHttpBinding_IUserAccountManagementService"


contract="UserAccountManage.IUserAccountManagementService"


name="WebHttpBinding_IUserAccountManagementService" />


<endp
oint address
="http://e14
-
sp04.contoso.com:8080/Microsoft.Hosting.SharePoint2010.Services
/SharePointManagementService.sv
c"


binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IManagementService"


contract="SharePointMa
nagement.IManagementService"
name="WSHttpBinding_IManagementService">


<identity>


<servicePrincipalName value="
HOST/E14
-
SP05.contoso.com
" />


</identity>


</endpoint>


<endpoint bindin
g="customBinding"
bindingConfiguration="WebHttpBinding_IManagementService"


contract="SharePointManagement.IManagementService"
name="WebHttpBinding_IManagementService" />



<endpoint address="
http://e14
-
sp04.contoso.com:8080/Microsoft.H
osting.SharePoint2010.Services

/SharePointQueryService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IQueryService"
contract="SharePointQuery.IQueryService" name="WSHttpBinding_IQueryService">


<identity>


<servicePrincip
alName value="
HOST/E14
-
SP05.contoso.com
" />


</identity>


</endpoint>


</client>


In the project properties, choose the SharePoint site to deploy to

(if SharePoint is local to VS)
. Add the
Microsoft.Hosting.SharePoint2010.UserAccountsWebParts_UserAccountsFeature

feature to your
feature packs.

If you are deploying this to a remote SharePoint instance, copy the project output to that server and run
the following script to deploy the solution,
using the path to the copied wsp file:

Add
-
SPSolution
"C:
\
Code
\
Microsoft.Hosting.SharePoint2010
\
Microsoft.Hosting.SharePoint2010.UserAccountsWebPart
s
\
bin
\
Debug
\
MsftHostingUserAccountsWebParts.wsp"

Install
-
SPSolution

Identity MsftHostingUserAccountsWebPar
ts.wsp

WebApplication http://e14
-
sp05

GACDeployment

Install
-
SPFeature
Microsoft.Hosting.SharePoint2010.UserAccountsWebParts_UserAccountsFeature

-
force

Install
-
SPFeature
Microsoft.Hosting.SharePoint2010.UserAccountsWebParts_UserAccountsFeatureStaple

-
for
ce


Then add the

Microsoft.Hosting.SharePoint2010.UserAccountsWebParts_UserAccountsFeature

feature
to your feature packs.

Create a tenant admin site and enable the feature on a Tenant Admin site collection:

Enable
-
SPFeature
-
identity 351c04d1
-
4b30
-
415d
-
b75
b
-
8df30bcea485
-
URL
http://intranet.northwind.com/admin
-
force

Microsoft.Hosting.SharePoint2010
.TenantAdmin

This project can only be compiled on a machine that has SharePoint 2010 installed. Build and deploy.
If
not already done for the User Account sample
,

add the following to the SharePoint Web Application
web.config’s appSettings settin
g
s, editing the
ManagementS
erver

value
:


<add key="ManagementServer" value="
e14
-
sp05
" />


If not already done for the User Account sample
,

add the system.servicemodel a
dditions as described in
the User Account sample above.

In the project properties, choose the SharePoint site to deploy to (if SharePoint is local to VS). Add the
Microsoft.Hosting.SharePoint2010.TenantAdmin_DiskQuota

feature to your feature packs.

If you
are deploying this to a remote SharePoint instance, copy the project output to that server and run
the following script to deploy the solution, using the path to the copied wsp file:

Add
-
SPSolution
"C:
\
Code
\
Microsoft.Hosting.SharePoint2010
\
Microsoft.Hosting.SharePoint2010.
TenantAdmin
s
\
bin
\
De
bug
\
Microsoft.Hosting.SharePoint2010.TenantAdmin.wsp
"

Install
-
SPSolution

Identity
Microsoft.Hosting.SharePoint2010.TenantAdmin.wsp


WebApplication
http://e14
-
sp
05

GACDeployment

Install
-
SPFeature
Microsoft.Hosting.SharePoint2010.TenantAdmin_DiskQuota

-
force

Install
-
SPFeature
Microsoft.Hosting.SharePoint2010.TenantAdmin_FeatureStaple

-
force


Then add the

Microsoft.Hosting.SharePoint2010.TenantAdmin_DiskQuota

feature to your feature packs.

Create a tenant admin site and enable the feature on a Tenant Admin site collection:

Enable
-
SPFeature
-
identity
1c77e519
-
3c45
-
4f2d
-
8f9f
-
755b4cbb6913

-
URL
http://intranet.northwind.com/admin
-
force



Running the Sample

With t
he exception of the Farm Tenant Services page, the remaining pieces of the sample panel assume
the farm has been setup for multi
-
tenancy and will error
-
out if this is not the case.

Navigate to the control panel virtual directory and use the menu on the le
ft to navigate around. The
initial WCF call will be slow as Windows PowerShell remoting does incur some penalties but after that
initial call, the remoted object is cached for performance.