Surendra Sharma

Surendra Sharma

Search This Blog

Showing posts with label DOT NET. Show all posts
Showing posts with label DOT NET. Show all posts

Thursday, June 1, 2017

Solved : The content type of the response message does not match the content type of the binding

If you are adding any SOAP web service as just "Add Service Reference..." in Visual Studio and receiving below error at runtime in your code
System.ServiceModel.ProtocolException was unhandled
  Message=The content type text/xml; charset=utf-8,text/xml; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '<?xml version="1.0" encoding="UTF-8"?>

Follow below steps to fix this

  • Right click on VS project
  • Click on "Add Service Reference..."
  • Click on "Advanced..."
  • Click on "Add Web Reference..."
  • Enter service URL and click on Go arrow button
  • Enter Web Reference name and click on Add Reference
In short add SOAP service as a "Web Service" and don’t by just Service Reference in Visual Studio.

Please leave your comments or share this tip if it’s useful for you.

Wednesday, October 19, 2016

Sitecore database lesson 10 - How to test Sitecore Databases performance

Sitecore provides a handy test aspx page to check your database performance. You can download it from here.

You have to unzip it and copy-paste “databasetest.aspx” page in “Website” folder.

Access this page from browser like http://sitecorelessons/databasetest.aspx where sitecorelessons is the name of Sitecore instance.

This page provides 

  • SQL Server information which includes ProductVersion, FileVersion, WindowsVersion, ProcessorCount and PhysicalMemory.
  • Perform action on items 10,000 times and provide useful information like Action name, Min Time, Max Time, Average Time and Boundary Average Time for selected database.
  • Provides index information and allow to rebuild indexes.
Here is screenshot of this page output

Sitecore Database Performance Tool
Sitecore Database Performance Tool

I hope you like this Sitecore database lesson. Stay tune for more Sitecore database related articles. 

Please leave your comments or share this article if it’s useful for you.

Friday, June 10, 2016

How to rebuild index programmatically in Sitecore

We have DR(Disaster Recovery) environment and everyday SQL job taking Production WEB database backup and restoring it on next day on our DR SQL server.

We are using SOLR search in our project.

Due to this database restoration, index rebuild is required for SOLR search. Initially we are doing indexing manually on daily basis.

But later on I make this rebuild process automatically.

The easiest way to rebuild an index automatically is to create a scheduled agent that will call and run the below code.

There are two questions before do it automatically.
·         Do you want to rebuild particular items and its children?
·         Do you want to rebuild full indexing?

Rebuild Particular Item and its children

You can use Refresh() method that will take few minutes for execution:
/// <summary>
/// Rebuild Index
/// </summary>
/// <returns></returns>
public string RebuildIndex()
    string result = string.Empty;

        result = "Custom Index Rebuild Process Start : " + System.DateTime.Now.ToString() + System.Environment.NewLine;

        foreach (Sitecore.Caching.Cache cache in Sitecore.Caching.CacheManager.GetAllCaches())

        result += "Cache completed : " + System.DateTime.Now.ToString() + System.Environment.NewLine;

        Sitecore.ContentSearch.ISearchIndex index = Sitecore.ContentSearch.ContentSearchManager.GetIndex("sitecore_web_index");
        if (index != null)
            result += "Home Indexing : " + System.DateTime.Now.ToString() + System.Environment.NewLine;

            string homeID = "{97FF4F41-A5FD-4BC3-838F-6A01E0E26B18}";   //Home
            index.Refresh(new Sitecore.ContentSearch.SitecoreIndexableItem(Sitecore.Data.Database.GetDatabase("web").GetItem(new Sitecore.Data.ID(homeID))));


        result += "Indexing completed : " + System.DateTime.Now.ToString() + System.Environment.NewLine;
    catch (System.Exception ex)
        result += ex.ToString() + System.Environment.NewLine;

    Sitecore.Diagnostics.Log.Error(result, this);

    return result;
Rebuild Full Indexing

You can use Rebuild() method that will also take few minutes for execution.

Sitecore.ContentSearch.ISearchIndex index = Sitecore.ContentSearch.ContentSearchManager.GetIndex("sitecore_web_index");
if (index != null)

What’s the difference between Rebuild() and Refresh() method?

The Refresh method allows you to update the full index or a part of it. The FullRebuild method deletes the index completely and builds it starting from the root.

The Refresh method also seems to be correct method to update the index, but if you need to rebuild the index completely, try Rebuild(Sitecore.ContentSearch.IndexingOptions.ForcedIndexing) - you should see the changes after as it forces the index rebuild.

Please leave your comments or share this trick if it’s useful for you.