The service '/Sample/SampleService.svc' cannot be activated due to an exception during compilation. The exception message is: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.

by Michel 17. September 2009 13:55

Getting the error below in your eventlog and do you have multiple identities for your website (i.e: sample.domain.tld & localhost)?

Event Type:        Error
Event Source:     System.ServiceModel 3.0.0.0
Event Category: WebHost
Event ID:           3
Date:                 16-9-2009
Time:                 8:46:15
User:                  NT AUTHORITY\NETWORK SERVICE
Computer:          COMPUTERNAME
Description:
WebHost failed to process a request.
Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/40535505
Exception: System.ServiceModel.ServiceActivationException: The service '/Sample/SampleService.svc' cannot be activated due to an exception during compilation.  The exception message is: This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection.

You could solve this issue by adding the following config section to your web.config:

    <system.serviceModel>
        ...
        <serviceHostingEnvironment>
            <baseAddressPrefixFilters>
                <add prefix="http://sample.domain.tld/Sample/"/>
            </baseAddressPrefixFilters>
        </serviceHostingEnvironment>
        ...
    </system.serviceModel>

Tags:

C# | Debug | .Net | WCF

Error Logging Modules and Handlers for ASP.NET (elmah)

by michel 18. May 2009 20:37

A while ago a friend a my promoted ELMAH via Live messenger, since then I am a FAN! ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.

Exceptions caught by ELMAH can be stored in memory, loose xml, VistaDb, Access, SQLLite, Oracle, MS Sql, or directly send by email. Storage- & mail configuration is done via the web.config.

The source of ELMAH is available and under the Apache License 2.0.
More info @: http://code.google.com/p/elmah/

In this post I’ll do an new implementation of the ELMAH Errorlog class to facilitate the MS SQL error logging with MOSS elevated privileges to solve the following problem.

The RunWithElevatedPrivilegesmethod will executes the specified code with Full Control rights even if the user does not otherwise have Full Control. In the MOSS environment it will execute the code under control of the the Application Pool Identity User. Implementing this method is really easy:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
   // put your code in here :)
});

The first step is to setup a class in Visual Studio (my example SqlErrorLogWEP (Sql ErrorLog With Elevated Privileges) and implement the abstract Errorlog class.

namespace Elmah
{
    using System;

    class SqlErrorLogWEP : ErrorLog
    {
        public override string Log(Error error)
        {
            throw new NotImplementedException();
        }

        public override ErrorLogEntry GetError(string id)
        {
            throw new NotImplementedException();
        }

        public override int GetErrors(int pageIndex, int pageSize, IList errorEntryList)
        {
            throw new NotImplementedException();
        }
    }
}

Because our SqlErrorLogWEP looks really for 99,9% like the classic SqlErrorLog class. In fact our class will act as a wrapper to implement the MOSS elevated privileges functionality for the SqlErrorLog class. To do this our constructor will initialize the (classic) SqlError log class and use the private sqlErrror object to perform the database logging. The above methods which still need to be implemented will use the sqlError object to do the work.

Our new class will look like this:

namespace Elmah
{
    using System;
    using System.Text;
    using System.Collections;
    using Microsoft.SharePoint;
    

    class SqlErrorLogWEP : ErrorLog
    {
        SqlErrorLog sqlErrorLog;

        public SqlErrorLogWEP(IDictionary config)
        {
            sqlErrorLog = new SqlErrorLog(config);
        }

        public SqlErrorLogWEP(string connectionString)
        {
            sqlErrorLog = new SqlErrorLog(connectionString);
        }

        public override string Log(Error error)
        {
            string retVal = String.Empty;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                retVal = sqlErrorLog.Log(error);
            });

            return retVal;
        }

        public override ErrorLogEntry GetError(string id)
        {
            ErrorLogEntry retVal = default(ErrorLogEntry);

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                retVal = sqlErrorLog.GetError(id);
            });

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
               // put your code in here :)
            });
            return retVal;
        }

        public override int GetErrors(int pageIndex, int pageSize, System.Collections.IList errorEntryList)
        {
            int retVal = -1;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                // put your code overhere 
            });

            return retVal;
        }
    }
}

Pro’s  / Con’s
Pro’s: Implementation in 2 minutes, completely ELMAH proof, extendable.
Con’s: Instead of only deploying the ELMAH assembly you will have an extra reference to the Microosoft.SharePoint assembly.

Tags: , , ,

.Net | C# | Microsoft | SharePoint | Tooling

New version Ajax Control Toolkit (.NET 3.5)

by michel 18. May 2009 19:12

asp.net Ajax The AJAX Control Toolkit is a joint project between the community and Microsoft. Built upon the ASP.NET 3.5 AJAX Extensions, the Toolkit aims to be the biggest and best collection of web-client components available.
The Toolkit addresses three needs. First it gives website developers a place to get components to make their web applications spring to life, second it gives a set of great examples for those wishing to write client-side code, and third it is a place for the best script developers to get their work highlighted.

Version number: 3.0.30512

info: here!

Tags: , , ,

Microsoft | .Net

Webservice: The test form is only available for requests from the local machine

by michel 14. January 2009 13:30

Receiving the the above message while trying to test your .NET web service remotely? Try to add the follwing xml snippet in the right place of your web.config file.

<system.web>
    <webServices>
        <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
</system.web>

 

happy coding :)

Tags: , , ,

Debug | .Net

The server sent a response which SharePoint Designer could not parse

by michel 17. December 2008 08:13

At this moment I'm building different kind of webparts for MOSS 2007. Some of these webparts are using the nice new fancy .Net 3.5 stuff. Because webparts are running in the SharePoint context you need to upgrade SharePoint to .Net .5 to get it to work.

Thanks to Jan Tielen I found an easy way to do this, hereby the 6-step tutorial:

  • Start Visual Studio 2008.
  • Create a new dummy ASP.NET Web Application Project, and make sure you target the .NET Framework 2.0 (upper right dropdown of the New Project dialog). The name of this project is not important; you won’t need it anymore when we’re done.
  • Copy the web.config of your SharePoint 2007 site, into the dummy Web Application project in Visual Studio.
  • Open the Project Properties in Visual Studio (right click on the Project node in the Solution Explorer, and choose Properties; or in the Project menu, select WebApplicationX Properties).
  • Select .NET Framework 3.5 in the Target Framework dropdown (select Yes in the confirmation dialog).
  • Copy the web.config from the Web Application Project back to SharePoint.

After doing this I did some testing inside SharePoint. Everything seemed to work. Until the next day...

The day after I needed to some things with my 'favorite tool' "SharePoint designer". I connected to my test-machine and try to open a aspx-file inside the designer (the application tree was shown as normal). I got the following error:

The server sent a response which SharePoint Designer could not parse. If you are trying to connect to a Windows SharePoint Services server, check with the server's administrator to make sure Windows SharePoint Services is installed properly.

Because I just upgraded the to .NET 3.5 , I knew the cause would be somewhere in the web.config file. After some digging  found out that inside the httpHandlers something went wrong:

<httpHandlers>
    <remove verb="GET,HEAD,POST" path="*"/>
    <add verb="GET,HEAD,POST" path="*" type="Microsoft.SharePoint.ApplicationRuntime.SPHttpHandler, ....."/>
    <add verb="OPTIONS,PROPFIND,PUT,LOCK,UNLOCK,MOVE,COPY,GETLIB,PROPPATCH,MKCOL,DELETE,(GETSOURCE),....."/>
    <add verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.Http....."/>
    <add verb="*" path="_vti_bin/ReportServer" type="Microsoft.ReportingServices.SharePoint.Soap.RSP....."/>
    <add verb="*" path="Reserved.ReportViewerWebPart.axd" type="Microsoft.ReportingServices.SharePoi....."/>
    <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFacto....."/>
    <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHa....."/>
    <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, ....."/>
    <remove verb="*" path="*.asmx"/>
</httpHandlers>

 

The <remove verb="*" path="*.asmx"/> key is removing the ScriptHandlerFactory (3 lines above) registration.

Solving is easy, move the <remove verb="*" path="*.asmx"/> key up to the top just below the <remove verb="GET,HEAD,POST" path="*"/> key. In this example your httpHandler section would look like this:

<httpHandlers>
    <remove verb="GET,HEAD,POST" path="*"/>
    <remove verb="*" path="*.asmx"/>            
    <add verb="GET,HEAD,POST" path="*" type="Microsoft.SharePoint.ApplicationRuntime.SPHttpHandler,....."/> 
<
add verb="OPTIONS,PROPFIND,PUT,LOCK,UNLOCK,MOVE,COPY,GETLIB,PROPPATCH,MKCOL,DELETE,(GETSOURCE)....."/> <add verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.Htt....."/> <add verb="*" path="_vti_bin/ReportServer" type="Microsoft.ReportingServices.SharePoint.Soap.RS....."/> <add verb="*" path="Reserved.ReportViewerWebPart.axd" type="Microsoft.ReportingServices.SharePo....."/> <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFact....."/> <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptH....."/> <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler,....."/>
</
httpHandlers>

 

Making changes in the Web.config will cause the application pool to restart, don't do this in a live productional system during working hours, restartig SharePoint takes ages :)

Tags: , , , ,

.Net | Debug | SharePoint

SharePoint unit testing without SharePoint!

by Michel 27. November 2008 08:22

Ever heard about TypeMock?? TypeMock is a tool which simplifies unit testing. As a not proffie unit testing I can tell that TypeMock is pretty easy to learn....

TypeMock has a pretty cool tool now for unit testing SharePoint, it´s called Isolator For SharePoint. It´s the only tool that allows you you unit test your SharePoint application without SharePoint.

I do not have any experience with the tool yet, I´ll keep updates posted on this topic... Did you btw know that you can get a license for free??

So how do I get the Free License?J ust make a post on your blog or site about the latest Typemock product, that includes the below text:Typemock are offering their new product for unit testing SharePoint called Isolator For SharePoint, for a special introduction price. it is the only tool that allows you to unit test SharePoint without a SharePoint server. To learn more click here. The first 50 bloggers who blog this text in their blog and tell us about it, will get a Full Isolator license, Free. for rules and info click here.

Tags: , , ,

.Net | Debug | SharePoint | Tooling

Up the ramp

by michel 13. November 2008 07:37

Ever heard about the free, online, community-based learning program from Microsoft Ramp Up?

Specifically Designed Learning Plans
We understand that different development skills have different learning needs. That's why Ramp Up comprises multiple learning plans, each designed with the unique learning needs of different developers in mind. Whether you’re just starting your software development career or a seasoned professional wanting to build your skills on the latest Microsoft technology, Ramp Up bridges the gaps you want to close.

Trusted Experts Guide Your Way
Ramp Up is a program built by expert developers for developers. Each learning plan comprises of premium technical content developed by renowned experts—famous authors, MVPs, and developer community leaders.

Success Is the Destination
Upon completion, you will have built a solid foundation of professional development skills and increased your proficiency with Microsoft Visual Studio 2005 and the Microsoft .NET Framework 2.0. You will also earn a graduation award comprising discounted learning and certification offerings. That gets you recognized and marked for advancement.

 

At the moment they have a nice SharePoint 2007 developer and a Visual Studio 2008 course... go check it out!

Tags: , , ,

.Net | SharePoint | Microsoft

Microsoft Enterprise Library 4.1 is OUT

by Michel 13. November 2008 07:27

Tags: , ,

.Net | Microsoft

ADO.Net Services not showing anything in browser

by Michel 10. November 2008 10:59

Having the problem as well that, when you are testing your ADO.Net Services in Internet Explorer, the browser is not showing anything?

This 'error' occurs when the 'Turn on feed reading view' option is enabled. To disable this, do the following:

Open IE, go to Tools > Internet Options > Content > Feeds (Settings) > Un-tick 'Turn on feed reading view'

Turn on feed reading view enabled Turn on feed reading view Disabled

Turn on feed reading view Enabled

Turn on feed reading view disabled

 

kick it on DotNetKicks.com

Tags: , , , ,

.Net | C# | Debug

About the author

Michel TolMy name is Michel Tol. I'm a developer specialized in .NET technologies. Mainly focussing on SharePoint Technologies and web development. I am Certified Technology Specialist for MOSS 2007 -  Configuration, .Net Framework 2.0 - Web applications and Biztalk Server 2006 - Custom Applications.

View Michel Tol's profile on LinkedIn

  

E-mail me Send mail

Page List