Get your mirroring service up and running in 10 minutes or less using NuGet
Although you are free to implement the mirroring service to support any database you prefer, SuperOffice provides a complete implementation of the database mirroring interface as a NuGet package.
This walk-through will guide you through creating a new WCF service from scratch using the SuperOffice.Crm.Online.Mirroring package, and help you have a running service in just a few minutes.
These steps were documented using Visual Studio 2015.
Note
You can download the completed result of these steps on GitHub. View the DevNet-Database-Mirroring repository on GitHub.
Create a new WCF Service Application in Visual Studio
In Visual Studio, click File, then New, and then Project.
In the New Project dialog, expand the WCF section and select to create a new WCF Service Application.
In the Solution Explorer, delete the following files: IService1.cs, Service1.svc, and Service1.cs.
Before:
After:
Install the NuGet package
Open the Package Manager Console:
- Click Tools, then NuGet Package Manager, and then Package Manager Console.
Start the installation by typing:
Install-Package SuperOffice.Crm.Online.Mirroring
Verify that the packages have been added:
When you see the successfully installed message in the Package Manager Console, go back to the Solution Explorer.
Confirm that you have a new assembly references and that the following files have been added to your project: MirroringClientService.svc, MirroringClientService.cs, and Private.txt.
Open the package.config file and check that you now have the new Mirroring package and its 2 dependencies. Your package versions may be different, and that is OK.
Tip
During installation, you will see a lot of data scroll by in the NuGet Package Manager Console. The Package Manager inspects the SuperOffice.Crm.Online.Mirroring
package and tries to download and add dependencies to your project.
Key points during package installation
- package name (
SuperOffice.Crm.Online.Mirroring
) System.IdentityModel.Tokens.Jwt
dependencySuperOffice.Crm.Online.Core
dependency- successfully installed message
These are underlined with red in the following screenshot:
Update settings in web.config
The functionality in the MirroringClientService.cs file helps you resolve a tenant's context identifier to a particular database, create the database if necessary, discover and provide the service's ApplicationToken, as well as the private certificate key it must use to sign the token placed in the AuthenticationResponse message. However, you must still provide those key pieces of information in the project's web.config file.
appSettings section
SoAppId: set to client ID (application environment-specific)
ConnectionBase: the partial connection string used to connect your SQL Server host
MirrorDatabaseName: will be used as a template for accessing the specific database on that server based on the context identifier passed to this service from SuperOffice
PrivateFileKey: the name of the file that contains your private certificate key in the RSA XML <RSAKeyPair>
and <RSAKeyValue>
format. Critical for initial authentication!
You get the private certificate key for all environments from SuperOffice.
system.serviceModel section
Because synchronizing a database requires a lot of data, it's important to set size options to the maximum capabilities for the mirroring service.
A complete system.serviceModel configuration example:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment to
avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpBinding" scheme="https" bindingConfiguration="DbMirroring" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="DbMirroring"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647">
<!-- Uncomment the security element if experiencing 404 service not found or unavailable.-->
<!--<security mode="Transport"> <transport clientCredentialType="None" /> </security>-->
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="DatabaseMirroringProject.SuperOfficeMirror.MirroringClientService">
<endpoint binding="basicHttpBinding"
bindingConfiguration="DbMirroring"
contract="SuperOffice.Online.Mirroring.Contract.IMirroringClientService" />
</service>
</services>
</system.serviceModel>
The naming and linking of key items are annotated in the following image.
Expose service to a public secure URL
Open the service in a browser:
In the solution directory, right-click the MirroringClientServer.svc file, then click View in Browser.
Assuming everything is correctly in place, you will see the default IIS or IISExpress web service page.
Finally, you will want to expose this service to a public HTTPS URL for the SuperOffice Mirroring Task to access it.
This will be the URL you must give SuperOffice when registering your application. Remember to specify this URL as the Database Mirror URL, not the Redirect URL.