Blog - Microsoft .NET, ASP.NET, AJAX and more

ASP.NET 4.0 AJAX – Preview 4 – Client Templates

by Damien White 4/28/2009 12:21:39 AM

GearsA little over a month ago, Microsoft released the fourth preview of ASP.NET 4.0 AJAX.  This is the new release of the Microsoft AJAX Framework that will be released with ASP.NET 4.0.  We’re getting closer to the RTM release of .NET 4.0 (hopefully later this year), so I figured this would be a good time to start posting about ASP.NET 4.0 AJAX.  There are some very exciting things coming along with ASP.NET 4.0, and the ASP.NET AJAX component is no exception.  The best news about ASP.NET AJAX is that you can start using it today without having to wait for the full blown ASP.NET AJAX framework.  Keep in mind that these components are still in "preview" mode (meaning no Microsoft support), though they are usable at your own risk.  For more information, you can check out the license on CodePlex.

In this post, I’ll be talking about the client templates that can be found in the latest release.  Client templates are very powerful.  They are a key component for rich client-side applications.  Up until now, I have been using jTemplates, a client template solution plugin for jQuery.  If you aren’t familiar with jTemplates, check out Dave Ward’s article “Use jQuery and ASP.NET AJAX to build a client side Repeater.”  jTemplates is really a nice plugin, but it’s a bit disconnected from the flow of the page.  Enter ASP.NET 4.0 AJAX and the DataView control. More...

Shout it kick it on DotNetKicks.com Bookmark and Share
Tags: , , ,
Categories: AJAX | ASP.NET | JavaScript | WCF | REST
Actions: E-mail | Permalink | Comments (17) | Comment RSSRSS comment feed

ASP.NET AJAX Page Methods

by Damien White 9/7/2008 12:38:26 AM

Page Methods - Basic ExampleIf you've read things of mine, such as my Wrox Blox Hands On ASP.NET AJAX Control Toolkit, or posts on the ASP.NET Forums, you may have noticed I talk about using ASP.NET AJAX Page Methods lots of the time.  Lots of developers using ASP.NET AJAX overuse the UpdatePanel, or use it in situations where it doesn't make sense.  One example of this that I explore in my book is the comparison between using an UpdatePanel for a cascading drop-down effect vs. using the ASP.NET AJAX Control Toolkit's CascadingDropDown Control with Page Methods.  In short, the CascadingDropDown was far more efficient.  Most of the time the reasoning for choosing the UpdatePanel is that developers don't "think" about the repercussions of the UpdatePanel, nor do they think about other approaches to the problems they're trying to solve.  One of my favorite posts on UpdatePanels that I constantly refer developers to is Dave Ward's blog post titled "Why ASP.NET AJAX UpdatePanels Are Dangerous".  The post does a great job of discussing the point of UpdatePanel overuse and gives an example of using Page Methods for a task instead of the UpdatePanel.  Since I still encounter developers who fall into the UpdatePanel trap, I figured it would be a good idea to discuss Page Methods a bit further.

More...

Shout it kick it on DotNetKicks.com Bookmark and Share

Excellent Reading Material - MSMQ, WCF, and IIS

by Damien White 8/21/2008 9:57:15 PM
Technorati Tags: ,,

If you are working with a WCF service, an MSMQ binding, and hosting in IIS, there are three wonderful articles by Tom Hollander that you should check out.  The series is entitled "MSMQ, WCF and IIS: Getting them to play nice", here are the three links:

They sure have helped me get one of my projects working, and I'm sure they will help you as well.

Shout it kick it on DotNetKicks.com Bookmark and Share
Tags:
Categories: .NET | WCF
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

ObjectDataSource, SOA Style

by Dave Marini 8/18/2008 11:43:00 PM

It's been entirely too long since my last post, and with the olympics in full swing, we'll go with a volleyball theme for this post.


BUMP

So here's the scenario. After really digging your teeth into ASP.NET 2.0 and playing around wiih all the cool data access features, you decide to apply a liberal use of the ObjectDataSource for its ability to take care of the paging and sorting calls for you. Now, you begin to convert your site to a service oriented back end and you wonder how you're going to make calls against your web service. You have a few options in front of you. You can create a thin facade layer that will act as a liaison between your presentation code and your service layer calls, and hook your ObjectDataSource to that. This works especially well when you have a complex object model that makes use of the web service calls behind the scenes. It's also beneficial when you are generating your proxy classes from metadata or contacting a foreign web service. In the scenario I'm going to demonstrate here, I'm referencing a shared contract and service library, so I'll be using using the ObjectDataSource to make direct calls to ChannelFactory<T> for this example.

More...


Shout it kick it on DotNetKicks.com Bookmark and Share
Tags:
Categories: .NET | ASP.NET | C# | Reflection | WCF | Web Services
Actions: E-mail | Permalink | Comments (1) | Comment RSSRSS comment feed

Metadata Exchange Using SvcUtil: A Cautionary Tale

by Dave Marini 3/21/2008 7:42:00 AM


One of the projects that I've been working on the past week is a conversion project that involves a web site that has a tightly coupled business logic layer. The goal of the project is to re-engineer the site so that the business logic and corresponding data access tiers are decoupled and distributed as services. For us the obvious choice for this is using the new Windows Communication Foundation framework to accomplish the task. After some heavy reading and a lot of trial and error, we're very close to having this done and I'm proud of the outcome given the short span of the project (~ 5 weeks). We probably could have finished in 4 weeks if it weren't for a seemingly innocuous problem with proxy generation that ended up costing me 3 day's time to solve.  If you're using a tcp based Metadata Exchange binding and having trouble generating a service proxy with SvcUtil, read on!

The Error Rears It's Ugly Head

This is the error that I was getting when trying to have SvcUtil generate my proxy class for a particular service of mine:

WS-Metadata Exchange Error   URI: net.tcp://localhost:8888/MyServices/MyBigFatGreekService

Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8888/MyServices/MyBigFatGreekService'.

The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:04:59.9843748'.

An existing connection was forcibly closed by the remote host

Oh how silly of me! As you can see, SvcUtil was built to tell you exactly what's going on, NOT!! this error is terribly vague because it leads you to believe that you have a network issue going on, which hey, you might. But in my case, I had 15 services hosted on the SAME address and I was able to generate 14/15 with no problem. Now, let's take a look at what kind of problems cause this error to appear:

Common Beginner Mistakes

I'm going to take a small digression here to talk about some common mistakes that take 30 seconds to fix that could cause this error to occur.  Most people who get errors from SvcUtil are missing something in the configuration of their services that is causing the problem.  The biggest two culprits I've seen:

1.) Make sure you enable Metadata Exchange. you need to do this explicitly for each service and it's commonly missed. This is done with a Service Behavior Configuration Section, like below. The key piece here is the serviceMetadata element:

<behaviors>
     <serviceBehaviors>
          <behavior name="MetaDataBehavior">
            <serviceMetadata />
          </behavior>
     </serviceBehaviors>
</behaviors>

If you're using a Tcp based binding, just making sure it's there as above enables the exchange. For using an Http based binding, specify either HttpGetEnabled or HttpsGetEnabled, as in the below example:

<serviceMetadata httpGetEnabled="true" />

2.) Make sure that the security settings on your binding match what you want to achieve.  If the discovery of your metadata is to be public, explicitly set your security to "None" so that you are sure not to encounter authentication issues. If not, make sure you configure the security correctly. In my example, we're not securing the metadata endpoint.

<services>
   <service name="Service.MyService" behaviorConfiguration="MyServiceBehavior">
      <host>
        <baseAddresses>
           <add baseAddress = "net.tcp://localhost:8888/MyService" />
        </baseAddresses>
      </host>
      <endpoint address="" binding="netTcpBinding" contract="Service.IMyService" 
           bindingConfiguration="myNetTcp" />
      <endpoint address="mex" binding="netTcpBinding" contract="IMetadataExchange" 
           bindingConfiguration="mexTcp" />
   </service>
</services>
<bindings>
  <netTcpBinding>
     <binding name="myNetTcp" portSharingEnabled="true">
     </binding>
     <binding name="mexTcp" portSharingEnabled="true">
         <security mode="None" />
     </binding>
     </netTcpBinding>
</bindings>

In this case I'm using port sharing because we want all of our services to share the same Tcp port regardless of how many we have in the future. If you have port sharing enabled for one service, do yourself a favor and keep it consistent. For more detailed information about port sharing, read this blog post by Nicholas Allen to get a true understanding of why you need this.

Sleuthing About

None of my other services were having proxy generation problems, so I knew that I had the services set up correctly. I even double checked to make sure I didn't have any syntax errors on that one service that could cause me problems. After this, I began seeing some strange things. Turns out, switching to an Http based binding like mexHttpBinding fixed the problem. But I didn't want http, I wanted Tcp, so I pressed on. What could be the difference between the two bindings that could cause such a problem?

It turns out that the service I had trouble with was the largest of all the services I was trying to generate (~ 30 methods). I found that by commenting out a few of the methods in the service contract, the Tcp Metadata exchange WORKED! It also didn't matter which methods were commented, which ruled out problems like an incorrectly serialized type or a duplicate operation name.  Now, in Juval Lowy's book on WCF, he states that service contracts should have no more than 5 - 7 methods if they are properly factored and this makes sense,  but I didn't have time to factor this class straight away due to time constraints.  For now, the class has to stay big. There was no documentation stating that service contracts had a maximum size restriction, so again, WHY THIS ERROR?

I thought that maybe I needed to up the default throttling controls on the metadata exchange binding for the services, so I increased the maxReceivedMessageSize and all of the limits in the readerQuotas element, but received the same error. It should be noted here that the mexTcpBinding is a very specific type of netTcpBinding that doesn't allow you to tweak these settings. So, just use netTcpBinding, there's no rule against it.

Send In The Marines!

Hey everyone, SvcUtil has a limit on how much metadata it can receive! Did you know that?  If you did, congratulations, because this is not well documented at all! Especially disconcerting is the apparent inconsistency with which this limit is imposed, which was the reason that my mexHttpBinding worked without a hitch. How do we tell SvcUtil to eat more fiber?  It turns out I was on the right track with increasing the throttling controls on the binding, but not in the right place. It turns out that I needed to create an app.config for SvcUtil itself, place it in the directory with SvcUtil.exe and THEN run it. Here's the config that finally made it work:

<configuration>
  <system.serviceModel>
     <client>
        <endpoint name="net.tcp" binding="netTcpBinding" bindingConfiguration="myTcp"
          contract="IMetadataExchange" />
     </client>
     <bindings>
        <netTcpBinding>
            <binding name="myTcp" maxBufferPoolSize="60000000" maxBufferSize="60000000" 
                 maxReceivedMessageSize="60000000" >
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                 maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
                 maxNameTableCharCount="2147483647" />
            </binding>
        </netTcpBinding>
     </bindings>
  </system.serviceModel>
</configuration>

So there it is. Make sure that the binding configuration that you use in the svcutil app.config matches the one you're using in the configuration file for your service host. If you don't, you will be getting a different error when you run SvcUtil, explaining that you have mismatched service settings and therefore the action is invalid.

Roll Credits

I can't say I figured this problem out on my own. In fact, when I was so frustrated that I ripped all my hair out, I finally posted the MSDN Forums to see if ANYONE had the same problem as me. Thanks to the moderators there, I was pointed in the right direction which solved my problem. You can see my post here.

In my next post, I'll be discussing why Visual Studio's Service Reference Proxy Generation Tool isn't adequate for those who are producing and consuming their own services and want to share multiple collection data types between the service and client, and how to use SvcUtil to overcome that inadequacy.

Shout it kick it on DotNetKicks.com Bookmark and Share