Monthly Archives: January 2006

Migrating ASMX to WCF

One question I was often asked last week was: “I have a bunch of ASMX services today, what is the best way for me to prepare for and/or migrate to Indigo”? (also asked as “can you tell me more about this ASMX migration thing?”). There are a number of ways to go about this, but Kirk and I came across a compelling approach that I will elaborate on here. Before we begin, if you need some background on the differences between ASMX 1.0, ASMX 2.0, and WCF, check out Aaron Skonnard’s MSDN article.

First we assume that you have a ASMX service implemented using CodeBehind. If you don’t, then your first step is to move your inline .asmx code into a .cs file 🙂

Now, let’s say you have the following ASMX service:

[WebService(Namespace=”http://kennyw.com/sampleservices/”)]
public class MyService : System.Web.Services.WebService
{

[WebMethod]
public string Hello(string name)
{

return string.Format(“Hello {0}.”, name);

}

}

Which is referenced from an .asmx file containing the reference directive such as the following:
<%@WebService Language=”C#” class=”MyService” %>

You can expose this ASMX service to WCF in 3 simple steps.

  1. Annotate your ASMX service with WCF attributes.
    Add [ServiceContract] to the classes you want to expose through WCF, and [OperationContract] to the methods. Our modified class looks like:

    [ServiceContract(Namespace=”http://kennyw.com/WCFservices/”)]
    [WebService(Namespace=”http://kennyw.com/sampleservices/”)]
    public class MyService : System.Web.Services.WebService
    {

    [WebMethod]
    [OperationContract]
    public string Hello(string name)
    {

    return string.Format(“Hello {0}.”, name);

    }

    }

  2. Create a .svc file in your virtual directory that contains the following declaration (which is very reminiscent of your .asmx file :)):
    <%@ServiceHost Language=”C#” Service=”MyService” %>
  3. Add a snippit to your web.config file (create one if you don’t already have one in your vdir) to add an HTTP binding for your service:
    <system.serviceModel>
      <services>
        <service type=”MyService”>
          <endpoint binding=”basicHttpBinding”
            contract=”MyService”
          />
        </service>
      </services>
    </system.serviceModel>

Viola! Now you can access your service file using both Indigo clients (using the .svc file) and ASMX clients (using the .asmx file). This will get you started on the migration path. You can add more functionality to other methods and expose those methods to new Indigo clients, and if you aren’t using any “HTTP-isms” (i.e. HttpContext.Current and friends) then you will also be able to add net.tcp and/or net.pipe bindings on Vista.

There are of course many more details to cover on this topic. For those going to VSLive! next week, Steve Maine will be covering this topic in much greater detail at the WCF for ASP.NET Developers session. Hopefully he will post some of his wise words following the talk on his blog 🙂

IDuplexSession.CloseOutputSession

When writing an IDuplexSessionChannel, one of the pieces that needs to be implemented is (as you might expect) IDuplexSession. IDuplexSession has one additional requirement on top of ISession, and that is the ability to perform a “half-close”. Semantically this is the same as Shutdown(Send) in sockets-speak.

When you call IDuplexSession.CloseOutputSession(), this signals to the other side of the session that it should return null from outstanding and subsequent calls to Receive(). CloseOutputSession() is also idempotent (just like ICommunicationObject.Close() and ICommunicationObject.Abort()).

CloseOutputSession() is also a little tricky, because it’s a session method that can interact with the owning IDuplexSessionChannel that owns the session. In particular, if your session lifetime is coupled with your channel lifetime (like it is for TCP and RM and Security):

  1. If CloseOutputSession() is called before channel.Close(), channel.Close() should wait for CloseOutputSession() to finish.
  2. If the channel is in the Created or Opening state, CloseOutputSession() should throw new InvalidOperationException(...).
  3. If the channel is in the Faulted state, CloseOutputSession() should throw new CommunicationObjectFaultedException(...).
  4. The channel should fault if CloseOutputSession throws.
  5. channel.Close() should call CloseOutputSession() and then verify that Receive() returns null (i.e. CloseOutputSession was called from the other side of the session).

Liuzza's by the Track (New Orleans, LA)

Rating:

Last night we went down to the French Quarter to see “…And the Ball and All” — a comedic farce about Mardi Gras. The evening started with some classic New Orleans fare: gumbo and poorboys. “Poorboy” (or “Po’ Boy”) is the locals term for a french roll filled with meat or seafood. A New Orleans hoagie if you will. According to the locals, the best places for po’ boys are all “hole in the wall”s. Liuzza’s is no exception.

It’s a dive near the train tracks a few blocks from where Jazz Fest is held. We squeaked in just before close (at 5PM), crowded around a small table, and ordered a bowl of gumbo and a pair of po’boys (fried oyster and barbeque shrimp). The gumbo was spicey and loaded with goodies (andouille sausage, chicken, shrimp, and oysters). The poorboys were definitely not for the feint of heart (medically speaking :)), but were tasty as can be. I was pleasantly surprised to discover “barbeque shrimp” in New Orleans doesn’t involve a tangy or vinegar-based sauce. Rather it’s more of a garlic-pepper sauce — think scampi on steroids with some extra pepper.

Liuzza’s by the Track
1518 North Lopez
New Orleans, LA 70119
504-943-8667

The Dakota Restaurant (New Orleans, LA)

Rating:

I flew into New Orleans yesterday to see my Dad who lives in Slidell, on the north shore of Lake Pontchartrain. Since he had just gotten a new tarp for the roof, all was clear for my visit.

After five months of rebuilding, things are starting to clean up. Not to say there isn’t a TON of work left, I can’t even begin to explain the extent of the devastation — a topic for another post.

The primary reaction I had gotten in Atlanta when I told them I was headed to New Orleans was “wow…the food there is amazing…” If the Dakota Restaurant is any indication, I can see why the cuisine in this city would make a lasting impression.

The ambience is romantic with a touch of chic. Dad told me that the dishes were moderately sized (i.e. I would actually be able to finish a soup and/or salad plus an entree). I started with one of their signature dishes: Lump Crabmeat and Brie Soup. It was thick and creamy and sinfully good.

I then got to sample two salads (fortunately my entire family encourages the “wandering fork syndrome”). Lynn ordered the Asian Ahi Tuna Salad — sushi grade ahi, sesame crusted, with a touch of soy and ginger. It was like they had taken a play from Wasabi Bistro’s cookbook and then upped the ante:

Asian ahi tuna salad

Dad’s roquefort salad was a finely executed version of LL’s salad template: [greens]+[nut]+[fruit]+[cheese] (in this case baby greens + roasted cashews + apples + roquefort).

Roquefort salad

For the main course I ordered the scallops. I can honestly say I’ve never seen scallops anywhere near as large. And yes, they were as yummy as they look — meaty and finely seared on top, served with wild mushroom ravioli in a foie gras sauce that added to the tastebud indulgence:

Monster tasty scallops

To complete the round up, Dad had the Parmesan crusted Tilapia (with crabmeat and fried artichoke), and Lynn had the grilled redfish. Both were very well executed and tastefully presented, with the sides complementing the fish (and our Gruner Veltliner) quite nicely. Overall a fantastic meal and a gastronomically sensational beginning to my weekend in New Orleans. This will be fun 🙂

The Dakota Restaurant
629 North Highway 190
Covington, LA 70433
985-892-3712

Mon-Fri 11:30AM-2:30PM (Lunch)
Mon-Th 5:00PM-10:00pm, Fri-Sat 5:00PM-11:00PM (Dinner)

Azio (Atlanta, GA)

Rating:

Outside of my hotel is a McDonald’s, a Hooters, and a Hard Rock Cafe. Not exactly the pinnacle of haute cuisine.

Tonight is my last night in Atlanta, and so I was determined to find a decent bite to eat. After circling a few blocks in different directions I only found a Steak and Ale, a chinese restaurant who’s sign was on the floor, some out of business retail spaces, and a number of people hitting me up for cash. Finally I turned the corner, walked past a seedy looking bar, and came upon a swank looking place with a decent looking menu. I decided to go inside and check out Azio’s.

I took a seat at the bar, and got to know KJ, the very friendly bartender. I started with the “insalada tricolore”, which was a mixed wild green, endive, gorgonzola and walnut salad with a slice of bruschetta. Yum.
insalada tricolore

I followed the salad with a very thin crust florentine pizza (spinach, mushroom, and Italian sausage). They bake their pizzas in a brick oven, which make the crust good and crispy. Overall a very tasty meal in a friendly environment. Thank you Azio!

florentine pizza
Azio
229 Peachtree St
Atlanta, GA 30303
404-222-0808

Mon-Fri 11:30AM-10:00PM, Sat-Sun 5:00PM-10:00pm
(Lunch and Dinner)