Connecting a WCF Service to an Model View Controller Client

Although MVC goes someway to separating the database layer, the business rules layer and the presentation layer – I need the first two to be available to a variety of client types (smartphone, slate, Desktop, Silverlight, Adobe Air) – As I am working on a prototype, using an MVC client that means connecting it to the WCF library.

Anyway I have written the Membership Provider and attempted to connect it to the WCF library.

1. Right click on the MVC Client Application

2. Select ‘Add Service Reference’

3. click on the ‘Discover’ button

4. Select the Service you want to connect (mine was called UserAccount.svc)

5. Change the namespace to something a little more descriptive than the default ‘ServiceReference1’

6. Click on the ‘OK’ button.

And this is where the problem started – I got the following error

The configuration for the service reference could not be added due to the following issue: An error occured creating the configuration handler for the system.serviceModel/behaviours: Extension element ‘enableWebScript’ cannot be added to this element. Verify that the extension is registered in the extension collection at system.serviceModel/extensions/behaviourExtensions. Parameter Nme: element (C:\Users\…..\web.config line 213)

Looking in the web.config I can see the following has been added

     <behavior name="Simplicita.Portal.Models.AccountModelsAspNetAjaxBehavior">
     <enableWebScript />

The problem seems to lie in the <enableWebScript> tag.

Basically you need to comment out the behaviour containing the enableWebScript Tag and try adding the service reference again, then remove the comment around the behaviour.  Not sure if this is a bug – it is a pain in the gluteus maximus. However once I did this then tried to add the service reference then it worked successfully. Once the service is added then remove the comment around the behaviour that was added earlier and the job is done.

The following is the ServiceModel tag from my client web.config once I had done the above;

        <binding name="BasicHttpBinding_IUserAccount" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
      <endpoint address="http://localhost:49333/UserAccount.svc" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_IUserAccount" contract="UserService.IUserAccount"
        name="BasicHttpBinding_IUserAccount" />
         <behavior name="Simplicita.Portal.Models.AccountModelsAspNetAjaxBehavior">
          <enableWebScript />
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
      <service name="Simplicita.Portal.Models.AccountModels">
        <endpoint address="" behaviorConfiguration="Simplicita.Portal.Models.AccountModelsAspNetAjaxBehavior"
          binding="webHttpBinding" contract="Simplicita.Portal.Models.AccountModels" />

Credit due to Ladislav Mrnka who gave me this solution on the MSDN forums.


2 thoughts on “Connecting a WCF Service to an Model View Controller Client

  1. Pingback: Using a Custom Membership Provider in an MVC Application « Developing My Cloud Application

  2. Pingback: 2010 in review « Developing My Cloud Application

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s