External tool of Visual Studio 2012 to test WCF at client

1. Go to the “Tools” of Visual Studio 2012 and select “External Tools…”

ExternalTools

2. Click “Add” and enter the command to “C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\WcfTestClient.exe”

WcfTestClient

3. Turn on “Enable anonymous access ” for your web application if you want to test WCF by Anonymous

Deploy SharePoint MVC App to Azure

Can we use ASP.NET MVC 4 for an App for SharePoint? Yes, we can. And bspann already gave us a very good details how to do this here. So, I do not talk about this again. What I want to say here is how can we develop and deploy an app on both “developer machine” and  “Azure” in same project. The scenario here is my developer machine using server-to-server to create a high trust app, and use a client secret in Azure.

My solution for this is using Web.config Transformation, which can help you develop and deploy your MVC web in somewhere. Here is the steps:

1. At the “Solution Configuration” of Visual Studio 2012, click into a “Configuration Manager…”

2. In “Configuration Manager”, click “New” and provide it a name

3. Right click on the “Web.config” in your MVC and select “Add Config Transform”

4. Now, you will see the new transform of this web.config named “web.AzureDebug.config”. Open the web.config and put some config in your appSeting like this:

1:   <appSettings>  
2:    <add key="webpages:Version" value="2.0.0.0"/>  
3:    <add key="webpages:Enabled" value="false"/>  
4:    <add key="PreserveLoginUrl" value="true"/>  
5:    <add key="ClientValidationEnabled" value="true"/>  
6:    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>  
7:    <add key="ProductID" value="6d510a27-38f7-4d0f-9e67-123456789012"/>  
8:    <add key="ClientSigningCertificatePath" value="C:\MyCert\HighTrustSampleCert.pfx"/>  
9:    <add key="ClientSigningCertificatePassword" value="yourP@ssw0rd"/>  
10:    <add key="IssuerId" value="8650ec6b-4e14-4747-9f8a-123456789012"/>  
11:    <add key="ClientId" value="6f8e094b-d6e6-40c4-b3b7-123456789012"/>  
12:    <add key="ClientSecret" value="AbCdEfGhIjKlMnOpQrAyxfU8zdZ+hAdT2wmu6ceuaJvkzfPnJQ="/>  
13:    <add key="DatabaseConnectionString" value="metadata=res://*/YourDatabase.csdl|res://*/YourDatabase.ssdl|res://*/YourDatabase.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=YourDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;"/>  14:    <add key="RemoteEndpoint" value="http://localhost:8888"/>  
15:    <add key="SharePointSiteUrl" value="http://sp/sites/online"/>  
16:    <add key="ServiceConfiguration" value="Local"/>  
17:   </appSettings>  

5. Open the “web.Debug.config” and edit the “system.web” to remove attributes from “release” and “azuredebug”

1:   <system.web>  
2:    <compilation xdt:Transform="RemoveAttributes(release,azuredebug)" />  
3:   </system.web>  

And, of course, edit appSettings

1:   <appSettings>  
2:    <add key="HostedAppHostNameOverride" xdt:Transform="Remove" xdt:Locator="Match(key)" />  
3:    <add key="ClientSigningCertificatePath" value="C:\MyCert\HighTrustSampleCert.pfx" xdt:Transform="Replace" xdt:Locator="Match(key)"/>  
4:    <add key="ClientSigningCertificatePassword" value="khongbiet_1" xdt:Transform="Replace" xdt:Locator="Match(key)"/>  
5:    <add key="IssuerId" value="8650ec6b-4e14-4747-9f8a-123456789012" xdt:Transform="Replace" xdt:Locator="Match(key)"/>  
6:    <add key="ClientId" value="6f8e094b-d6e6-40c4-b3b7-123456789012" xdt:Transform="Replace" xdt:Locator="Match(key)"/>  
7:    <add key="ClientSecret" value="AbCdEfGhIjKlMnOpQrAyxfU8zdZ+hAdT2wmu6ceuaJvkzfPnJQ=" xdt:Transform="Replace" xdt:Locator="Match(key)"/>  
8:    <add key="DatabaseConnectionString" value="metadata=res://*/YourDatabase.csdl|res://*/YourDatabase.ssdl|res://*/YourDatabase.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=YourDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" xdt:Transform="Replace" xdt:Locator="Match(key)"/>  9:    <add key="RemoteEndpoint" value="http://localhost:8888" xdt:Transform="Replace" xdt:Locator="Match(key)"/>  
10:    <add key="SharePointSiteUrl" value="http://sp/sites/online" xdt:Transform="Replace" xdt:Locator="Match(key)"/>  
11:    <add key="ServiceConfiguration" value="Local" xdt:Transform="Replace" xdt:Locator="Match(key)"/>  
12:   </appSettings>  

6. Open the “web.AzureDebug.config” and edit it the same way we did for “web.Debug.config”

In “system.web”

1:   <system.web>  
2:    <compilation xdt:Transform="RemoveAttributes(debug,release)" />  
3:   </system.web>  

In “appSettings”

1:   <appSettings>  
2:    <add key="HostedAppHostNameOverride" xdt:Transform="Remove" xdt:Locator="Match(key)" />  
3:    <add key="ClientSigningCertificatePath" xdt:Transform="Remove" xdt:Locator="Match(key)" />  
4:    <add key="ClientSigningCertificatePassword" xdt:Transform="Remove" xdt:Locator="Match(key)" />  
5:    <add key="IssuerId" xdt:Transform="Remove" xdt:Locator="Match(key)"/>  
6:    <add key="ClientId" value="48384dfb-52f9-4f04-9a53-123456789012" xdt:Transform="Replace" xdt:Locator="Match(key)"/>  
7:    <add key="ClientSecret" value="AbCdEfGhIjKlMnOpQrAyxfU8zdZ+Ulemc9Z6NM6TTKn51Xwu7/o=" xdt:Transform="Replace" xdt:Locator="Match(key)"/>  
8:    <add key="DatabaseConnectionString" value="metadata=res://*/YourDatabase.csdl|res://*/YourDatabase.ssdl|res://*/YourDatabase.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=tcp:quacquac.database.windows.net,1433;initial catalog=YourDatabase;persist security info=True;user id=khetkhet@quacquac;password=oeoe;MultipleActiveResultSets=True;App=EntityFramework&quot;" xdt:Transform="Replace" xdt:Locator="Match(key)"/>  9:    <add key="RemoteEndpoint" value="https://yourappsite.cloudapp.net" xdt:Transform="Replace" xdt:Locator="Match(key)" />  
10:    <add key="SharePointSiteUrl" value="https://yoursharepointsite.sharepoint.com/sites/online" xdt:Transform="Replace" xdt:Locator="Match(key)" />  
11:    <add key="ServiceConfiguration" value="Cloud" xdt:Transform="Replace" xdt:Locator="Match(key)" />  
12:   </appSettings>  

7. Rebuild your solutions to make sure everything is ok.

8. If you want to deploy your app to local, select “Debug” in “Configuration Manager” and rebuild. Then, right click on your app project and select “Publish…”. In “Publish Web” dialog, select “Profile” tab and create new profile named “MVCDebug”. At the second tab, choose the publish method and target location

Select “Debug” in configuration

Click “Publish” to publish your MVC web

9. In case you want to deploy it to Azure, you need to create new project type “Windows Azure Cloud Service”, do not select anything and click “OK”

Then, add “web role project in solution”

and select your MVC project

10. Rebuild your solutions with “AzureDebug” then right click on your AzureProject and select “Publish…”

10. Fill some information and click into “Publish”

Done!!!