How to Enable WCF Trace for SharePoint

July 24, 2014

Troubleshooting when things go wrong with your WCF application in a SharePoint environment can be a nasty task. SharePoint tends to hide the actual error giving you a service fault without actually telling you what’s happening. When we can’t get the error out of our NUnit tests that we run we have to enable WCF Tracing to figure out what’s going on. Here are the steps to perform this:

1) Find and open the web.config for the site that you are trying to debug. Most cases it’s located at C:\inetpub\wwroot\wss\VirtualDirectories\WebsiteName\web.config
2) Locate the line <system.serviceModel>
3) Add the following lines inside the node:

    <diagnostics>
          <messageLogging maxMessagesToLog="30000" logEntireMessage="true" logMessagesAtServiceLevel="true" logMalformedMessages="true" logMessagesAtTransportLevel="true"/>
    </diagnostics>

4) Next, add the following after the </system.ServiceModel>

    <system.diagnostics>
        <sources>
          <source name="System.ServiceModel" switchValue="Verbose, ActivityTracing" propagateActivity="true">
            <listeners>
              <add name="xml" />
            </listeners>
          </source>
          <source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
            <listeners>
              <add name="xml" />
            </listeners>
          </source>
          <source name="System.Runtime.Serialization">
            <listeners>
              <add name="xml" />
            </listeners>
          </source>
        </sources>
        <sharedListeners>
          <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="mytracelog.log" />
        </sharedListeners>
        <trace autoflush="true" />
    </system.diagnostics>

5) Save the file and perform an IISReset
6) Now test your service, using NUnit, Fiddler, SoapUI or whatever you’re using.
7) A file named ‘mytracelog.log’ will be created in the directory your web.config was located in.
8) Use a tool called SvcTraceViewer.exe to open and read the file. The exe comes with .Net sdk, which can be found at C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin. If it’s not there, download the Mircosoft SDK. Here is some more info on the SvcTraceViewer.exe.
9) Any errors that happen will show up in the viewer as highlighted lines.

If you’re using NUnit to test your service. You can add these lines to your NUnint web.config to enable trace for your test.

<system.serviceModel>
    <diagnostics>
      <messageLogging maxMessagesToLog="30000"
              logEntireMessage="true"
              logMessagesAtServiceLevel="true"
              logMalformedMessages="true"
              logMessagesAtTransportLevel="true">
      </messageLogging>
    </diagnostics>
  </system.serviceModel>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Verbose, ActivityTracing"
              propagateActivity="true" >
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging"
              switchValue="Verbose">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="xml"
           type="System.Diagnostics.XmlWriterTraceListener"
           initializeData="yourtracefile.log" />
    </sharedListeners>
    <trace autoflush="true" />
</system.diagnostics>

This helps take the guess work, and trial and error that you might do without enabling trace. It sure saved us a couple times.

Overriding the SharePoint Modal Dialog Close Button

July 16, 2014

The close button in a SharePoint modal dialog is built into SP.UI.ModalDialog and simply closes the dialog. However, we would like to run some backend code before the dialog closes.  Attempts to use the $clearHandlers and $removeHandler SharePoint functions to remove the original click handler have failed.

Workaround:

1. Create an ASP.NET Button control and hide it with css:

<asp:Button
    ID="btnClose"
    runat="server"
    text="Close"
    CssClass="hidden" />
.hidden {
    display: none;
}

2. Add a backend click event handler containing the code we want to run before the dialog closes, as well as code to close the dialog afterwards:

btnClose.Click += this.BeforeClose;

protected void BeforeClose(object sender, EventArgse )
{
    // stuff to do before close
    [...]

    // close the dialog
    var script = string.Format("window.frameElement.commonModalDialogClose({0}, '{1}');", 0, "Cancelled the dialog");

    this.Page.Response.Clear();
    this.Page.Response.Write("<script type=\"text/javascript\">" + script + "</script>");
    this.Page.Response.End();
}

3. Using JavaScript, remove the original SharePoint close button, create a new one using the same HTML, then add a click event listener which triggers a click on the ASP.NET Button control:

jQuery(document).ready(function() {
    // find the newly created ASP.NET Button
    var aspCloseButton = jQuery('input[id*="btnClose"]');

    // find the SharePoint dialog button container
    var spButtons = jQuery('.ms-dlgTitleBtns', window.parent.document);

    // find the SharePoint dialog close button and remove it
    spButtons.find('a.ms-dlgCloseBtn').remove();

    // append a new close button
    spButtons.append('<a accesskey="C" class="ms-dlgCloseBtn" title="Close dialog">' +
                     '<span style="padding: 8px; height: 16px; width: 16px; display: inline-block;">' +
                     '<span class="s4-clust" style="height: 16px; width: 16px; position: relative; display: inline-block; overflow: hidden;">' +
                     '<img class="ms-dlgCloseBtnImg" style="left: -0px !important; top: -645px !important; position: absolute;" alt="Close dialog" src="/_layouts/15/images/fgimg.png" />' +
                     '</span></span></a>');

    // add a click event handler to the new close button
    spButtons.find('a.ms-dlgCloseBtn').on('click', function() {
        if (aspCloseButton.length)
            // trigger a click on the ASP.NET button
            aspCloseButton.click();
        else
            // failsafe if the ASP.NET button is not found
            window.frameElement.commonModalDialogClose(0, 'Cancelled the dialog');
    });

SharePoint 2010 Document Property Promotion

July 3, 2014

Creating custom solutions such as a custom upload to a document library in SharePoint exposes some features that are very useful out of box, but problematic in our solution. One of these features that we recently discovered is Document Property Promotion.  Basically, upon calling SPFile.SaveBinary(), properties within Office documents are automatically extracted and saved to the list item’s corresponding columns in the document library. The issue we were running into was that the properties that we save during our custom upload process were being overwritten by the document’s properties.

The solution is to set SPWeb.ParserEnabled = false like below:

web.ParserEnabled = false;
web.Update();
item.File.SaveBinary(fileStream);
web.ParserEnabled = true;
web.Update();

However, we realized that this fails when the user that is logged in executing this code does not have administrative permissions. In the end, what worked for us was storing the custom programatically saved SPListItem properties before calling SPFile.SaveBinary() and then reapplying them after SPFile.Item.Update().

Marketing & Innovation: Key to Growth

We’ve known since the turn of the last century that marketing works. A good marketing approach with a solid campaign is truly the key to a healthy and sustained growth of any technology organization.

This idea is now further reinforced by the widespread growth of the internet as a research and education tool. We are spending more and more time online, and we are learning about everything.  So what does it mean?

Consumers Are More Informed

Let us use an example here. How many of us have walked into a dealership, completely clueless and depended entirely on the salesperson to help us figure out what kind of car we should be buying?  Probably no one between the ages of 20-50! Our education starts with social discussion and then goes online where we look at all the videos, read all about gas consumptions, safety, reliability, Lemmonator ratings, etc. When we stop over at the dealership, we are fully informed about the type of car we want. The salesperson has become merely a guide to take us from one lot to another so we can try out the feel of each model.

Guess what! Companies/consumers are expecting the same thing from a service organization! Our customers expect to go online and understand entirely what they are buying, how much it’s going to cost, how long it’s going to take, etc. The more that we can educate our customers on our services, approach, process, ideas and value, the better the chance that our phone will ring.

Marketing As an Education Tool

Our website is the most valuable marketing tool there is. This is not only the “glossy” of our services, it also contains the in-depth super-detailed information that the consumer needs to make a decision to pick up the phone and reach out. We are targeting both the CIO and the IT Manager, and appealing to multiple business teams to ensure that we, as a service provider, can be effectively evaluated and so that the potential customer has enough information to take the time to contact us to begin an engagement.

Competition is fierce today and our customers’ time is very valuable, so if a customer is not able to garnish enough information from our website, they might just move on to another provider who does have adequate information and call them.

Don’t Call Us, We’ll Call You — I don’t think so.

The idea of rows of sales people hitting a quota of 50 calls a day is rapidly becoming extinct. This concept is still effective, but only as an add-on to a proper marketing campaign and a solid service roster that provides good value for the customer.   The operative word there being “value”.  Let’s take a look at that for a minute:

Here is my (actually RefineCo’s) perspective on value:

  • Recommended based on previous experience.
  • Able to quickly and precisely assess the problem and tailor an appropriate solution without leading a customer on to think they need more.
  • Skilled personnel with excellent communication skills are involved in delivering the solution.
  • The solution is high quality, and does the intended job (fast, stable, reliable).
  • The service provider also provides a warranty for the work.
  • The service provider is able to educate (train, document, leave information) so that the customer does not have to rely entirely on the provider to support or augment the solution.
  • In the event where the customer wants to rely on the provider, the provider offers an excellent support model based on a standard process like ITILv3.

Now, for the customers to understand this, we need to provide them with a way to learn about us without necessarily us telling them about it.  This is where the website becomes such an important tool. It needs to offer both the 50,000 foot view, as well as the up-close detailed perspective on all these items.

Role of Sales Changes

​Even 10 years ago, it was enough to say “We Do Websites”; today we need to be very specific about the type of websites, and give the customer a clear view of the process and expectations BEFORE anyone gets in touch.

Sales is still important for the account management and human touch (customer experience), but the expectation of the sales person educating the customer on what will happen is changing.  The sales person becomes more of a guide to ensure that things are moving forward, rather than “upselling” to try to press upon the customer the value of the services that we deliver.

Innovation Separates You From the Rest

That leaves us with one last topic to cover. Assuming that all providers are made equal, and the half a dozen expectations of value are standard fare, what separates you from the swath of other providers vying for the same business? Correct, the answer is indeed innovation. Innovation today has become the single most important growth factor. Just to be clear, we are not just talking about writing solid software, a responsive interface, or inventing the pinch in a touch interface.  We are talking about innovations in process, ideas, approach to account management, marketing your services — literally everything. This is the key to your success.

So how do you ensure that you have a healthy dose of innovation in the services you provide and receive?

Hmm.. give us a call and we will show you  =)