IgorShare Thoughts and Ideas

Consulting and Training

Archive for the ‘WCF’ Category

Putting SOAP to REST – Cape Code .NET User Group @ Hyannis, MA

Posted by Igor Moochnick on 12/24/2009

I’d like to thank the Cape Code .NET User Group for giving me the opportunity to talk about SOAP and REST and, specifically, Todd Kittredge and Venture Hyannis for hosting the event.

I’ve posted the slide deck on the Slideshare:

 

[Update: 12/31/2009]

The landing page for the REST in WCF will point you to the location of the REST Starter Kit.

 

I’d like to remind you that everybody is invited to the upcoming Northeast Roadshow. You can find more information on Chris Bowen and Jim O’Neil blogs.

While these guys are working on the main Roadshow page, you can access their staging location for the near-final info.

Posted in REST, SOAP, WCF | 2 Comments »

Messaging Platform and Service Bus Resources

Posted by Igor Moochnick on 10/25/2009

On the recent project we’ve put in place a messaging platform. Apparently my engineers had a vague understanding what that is. To save you the same trouble I’ve gathered a bunch of interesting resources that can help you get up to date:

Open source Service Bus implementations

nServiceBus

MassTransit

WCF (misc)

Posted in Messaging, REST, Service Bus, WCF | Leave a Comment »

Now I have ALL of the Microsoft developer certifications – long journey is over!!!

Posted by Igor Moochnick on 09/09/2009

Now I own the full deck of the Microsoft certifications and I can sit back and relax (beer is in order ;-). Unfortunately, in the startup world that I operate most of the time, it’s not very recognizable achievement, but it’s nice to put these logos on my presentation slide decks and, especially now, I have a very powerful bragging rights – I have ALL of the Microsoft developers certifications !!!

It was a lengthy path and, I should add, a very confusing one. It wasn’t very obvious what certification is a prerequisite to which one and, I must add, I’ve made a couple of mistakes on the road until I’ve discovered a developer’s certification map by Jorgen Thelin that put everything in order and cleared all the confusions.

ms-cert-path-mcpd_4[1]

Posted in .NET, ADO.Net, ASP.NET, C#, Community, Thoughts, WCF, Workflows, WPF | 6 Comments »

WCF Certification (70-503) is mine!!! Now I’m a certified (MCPD) Enterprise Application Developer

Posted by Igor Moochnick on 09/06/2009

If you were wondering why there was a silence on my blog – I was preparing for a battle with the Prometric testing computer 😉 And I Won!!! Last week I’ve passed my LAST (for the near future) certification exam: Windows Communication Foundation. This gave me another MCT certification –

MCTS wcf

And finally enabled my long overdue certification MCPD Enterprise Application Developer.

MCPD ent

To those who are looking into passing this certification you may use the following materials that I found very helpful (after the break):

Read the rest of this entry »

Posted in .NET, Community, Thoughts, WCF | 13 Comments »

Building GWT web clients [Part 4.1] – How to create an Azure RESTful web service?

Posted by Igor Moochnick on 06/08/2009

Prerequisites: make sure that you have all the Azure SDK tools installed for your VS2008.

 

(1) Start by creating a new “Web Cloud Service” project in the Visual Studio. Give it a nice name.

(2) Add a new “WCF Service” to the WebRole project.

(3) Define a required contract:

The most important part here is to put attributes that will tell the WCF in what format to send/receive the message body (XML or JSON) …

[ServiceContract(Name = "service", Namespace = "http://www.igorshare.com")]
public interface IContactManagerService
{
    [OperationContract]
    [WebGet(UriTemplate = "/contacts", BodyStyle = WebMessageBodyStyle.Bare,
       ResponseFormat = WebMessageFormat.Json)]
    List GetAllContacts();

    [OperationContract]
    [WebGet(UriTemplate = "/contacts/{filter}", BodyStyle = WebMessageBodyStyle.Bare,
       ResponseFormat = WebMessageFormat.Json)]
    List GetContacts(string filter);
}

[DataContract]
public class Contact
{
    [DataMember]
    public string FirstName { get; set; }

    [DataMember]
    public string LastName { get; set; }

    [DataMember]
    public string Company { get; set; }
}

(4) Implement the service logic:

public class ContactManagerService : IContactManagerService
{
    private static readonly List Contacts = new List() { ... };

    public List GetAllContacts()
    {
        return Contacts;
    }

    public List GetContacts(string filter)
    {
        string f = filter.ToLower();

        var contacts = from contact in Contacts
                       where contact.FirstName.ToLower().Contains(f) 
                            || contact.LastName.ToLower().Contains(f)
                            || contact.Company.ToLower().Contains(f)
                       select contact;

        return contacts.ToList();
    }
}

(5) Configure it to be exposed as a RESTful service:

To make it REALLY, REALLY simple for you, do this trick:

a) Comment out the system.serviceModel section in the Web.config file

b) Add the Factory attribute to the .svc file


(6) Build the service

 

You’re interested in 2 artifacts of the build:

  1. .cscfg file – configuration for the Cloud Service deployment
  2. .cspkg file – all the bits packaged (zipped)

 

At this moment you have 2 choices:

  1. Run your project in the local Development Fabric (for testing and debugging), or …
  2. Deploy it to the Azure Cloud (for staging or production)

 

To deploy your application to the cloud, do right-click on the CloudService project and select “Publish”.

Visual Studio will launch the Azure Service Developer Portal page. Log-in to your account, create a project and deploy your bits to the staging environment:

clip_image001

 

This is it!  You’re good to go.

BTW: make sure that your application works in the staging environment and then you can push it to Production by just switching it with the Staging.

 

 

Note: Check out a great explanation about the difference between the WCF REST Configuration for ASP.NET AJAX and plain REST Services by Rick Strahl.

Posted in .NET, Azure, C#, Cloud, JSON, REST, Tutorials, WCF | 2 Comments »

CodeCamp 11 Presentation: Best Practices in building scalable cloud-ready Service based systems

Posted by Igor Moochnick on 03/29/2009

This Saturday I’ve held a “Best Practices” Zen-style discussion during the CodeCamp #11 in Waltham.

Some people were great, but I really expected to have more heated discussions and interesting “war” stories.

You can find the slide deck on the SlideShare

Posted in ADO.Net, Azure, Cloud, Data Services, Presentations, WCF, Web | Leave a Comment »

How does my Silverlight app finds it’s web services?

Posted by Igor Moochnick on 04/18/2008

In a simple case, your Silverlight app will be connecting to the same Web Site for the web services that hosts the app itself. So the app can take it’s Uri and replace the trailing document name with the WebService address.

Uri docUri = HtmlPage.Document.DocumentUri;
Uri svcUri = new Uri(docUri, "ServiceAdress.svc");

Note that this is a simplified code that explains the idea, so, please, do not hardcode any string constants in your code – it’ll be pretty hard to reconfigure your application later. Use configuration files.

Posted in C#, Silverlight, Tutorials, WCF, Web | Leave a Comment »

Exposing dynamic data via RSS feed

Posted by Igor Moochnick on 02/11/2008

In my recent article “RSS is not only for the news” I’ve mentioned that the current Syndication API is pretty flexible and allows a great deal of control of what is sent over the wire. This allows you to give the client almost anything it asks for. For example your application can provide a graphical information, a binary data, etc… Think about all the different way you can present your data.

Here is a simple example: let’s say you have a resource that is changing over the time (it can be traffic data). You can provide a link to this data and as soon as a user (or another service) navigates there – the data (for example, XML) can be streamed as a response. But what if it’s a real user and you want to be friendly and present this data in a graphical form (render the graph)? You can do that by just adding additional parameter to the URL that will tell your service what format the data can be (should be) presented in.

Remember the feed contract?

[ServiceKnownType(typeof(Atom10FeedFormatter))]
[ServiceKnownType(typeof(Rss20FeedFormatter))]
[ServiceContract]
public interface IFileChangeFeed
{
    // ... other operations

    [OperationContract]
    [WebGet(UriTemplate = "file?path={path}")]
    Stream GetFile(string path);
}

Note that the GetFile request has a URL parameter. In my case the parameter tells the service what file to retrieve, but in your case it can tell your service what data to generate and in what format. [Note: please don’t deploy this example on the real systems until you know EXACTLY how and who is accessing your feed. The sample, deployed AS-IS, exposes your system to the external attacks]

The URL request that will be routed to the GetFile method can look like this: http://yourHost/service/location/file?path=fileName.ext

The WCF will find a match in your contract and will call the GetFile method, substituting the “path” variable with the value of the “path” parameter.

public Stream GetFile(string path)
{
    if (File.Exists(path))
    {
        WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain";
        WebOperationContext.Current.OutgoingResponse.Headers.Add(HttpResponseHeader.ContentLength, 
             new FileInfo(path).Length.ToString());
        return new FileStream(path, FileMode.Open, FileAccess.Read);
    }
    else
    {
        WebOperationContext.Current.OutgoingResponse.SetStatusAsNotFound();
        return null;
    }
}

 

This is a pretty straightforward way to return back any type of data, depending on the incoming request. As you can see it’s extremely simple, so unravel your imagination and let REST be your friend!

BTW: Just found an MSDN article, HTTP Programming with WCF and the .NET Framework 3.5,  talks about similar issues and guides you through other REST-related examples.

Posted in C#, REST, Tutorials, WCF | Leave a Comment »

Announcement! Adventures of a WinForms developer in the WPF world

Posted by Igor Moochnick on 01/05/2008

image

Recently I start to see more and more adoption of the WPF around me, but it still happening very slowly. Mainly this is due to the extreme flexibility of the WPF and lack of the predefined control libraries. This is extremely bad for people who are perfectionists. They like to make their application shine, but can’t do this without a deep knowledge of WPF. And, while starting to learn WPF, they start to wonder around and discover more and more amazing things that can be achieved with it. It’s just impossible to stop and focus on the day-to-day tasks. Big companies can afford to have a dedicated designer, but a small dev or consulting shop can’t. And more than that, today there are only a handful of designers that know WPF in and out. Just admit it – the technology is still new and not widely adopted.

So, I’ve decided to walk you through all the small tips and tricks that I’ve passed through a year ago while playing with CTP bits of WPF and .NET 3.0. The tutorial will be based around a single application. I plan to show how different new .NET 3/3.5 technologies (WPF, WCF, WF) can be used in a series of small posts. Each time making the application smarter and more functional.

I think it’s a time to have a code alternative to Northwind database. If all the DB-related examples are written against Northwind, what are the DB-unrelated examples should be written against? Don’t you think?

I’ve put a screen-shot for a tease. If you can figure out what this application doing you can win a nice mug.

NOTE: If, by any chance this post will see a designer that knows WPF and want to join me in writing a nice WPF-related tutorials. Shoot me a note.

Posted in C#, Software, Thoughts, Tutorials, WCF, Workflows, WPF | Leave a Comment »

RSS is not only for the news

Posted by Igor Moochnick on 12/23/2007

The new Syndication libraries, provided in the .NET 3.5, making creation of the RSS feeds a walk in a park. By combining them with the power of the WCF you can get an amazing results.
RSS technology allows you to reverse the client/server tandem from push to pull paradigm. Instead of client sending data to server you can publish the available data and make server to decide what to pull(download) and what to ignore, This can save a lot of valuable resources like time, network bandwidth, data transfer and processing.

To make my case more interesting and appealing let’s imagine a situation where you want to make a back-up agent that will be archiving all the text files. In order to do so, all the desktops will publish all the newly changed files that need to be archived. The server will subscribe to all the relevant feeds. In this article I’ll cover, for starters, only the client’s side and in the following articles we’ll talk about different discovery and subscription mechanisms that we have in our disposal in .NET for the server.

The following snippet shows you how to create s simple syndication feed:

SyndicationFeed feed = new SyndicationFeed();
List items = new List();
…
SyndicationItem item = new SyndicationItem(title, path, GetFileUri(path));
items.Add(item);
feed.Items = items;

As you can see it’s extremely easy, but this was just a half of the job. The other half is to publish the feed. There are a lot of ways to do it, but I’m going to cover one of them. Since WCF is one of the best things to use in windows services (as well as in Web services), I’m going to use it to publish the feed. Here how you will initialize the WCF host with the Feed Service as a singleton (single-instance):

FileChangeFeedService service = new FileChangeFeedService();
ServiceHost serviceHost = new ServiceHost(service);
serviceHost.Open();

Note: don’t forget to mark the service class as a single-instance service by adding ServiceBehavior attribute –

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
IncludeExceptionDetailInFaults = true)]

Announce: I’ll be talking about REST in the following posts as well as a new “Give it a REST” presentation is ready for broader public to attend.One of the beautiful things that became available with .NET 3.5 is Url templates. This allows to put HTTP verbs on the methods of a web service as well as to map the Url parts (not only parameters) to a method parameters. This in many cases will eliminate any need for parsing of the data. All the mentioned above, make the WCF Web Services REST compatible.For example:

[OperationContract]
[WebGet(UriTemplate = “?format={format}”)]
SyndicationFeedFormatter Feed(string format);

This contract method will be called if a web request will come to the following URL:http://localhost/feed?format=rssThe format parameter (“rss” in our case) will be extracted from the URL and passed as a parameter to the Feed method. This allows us to seamlessly provide different feed formatting (thanks to the new WCF libraries):

public SyndicationFeedFormatter Feed(string format)
{
if ((format != null) && (format.ToLower() == “rss”))
return new Rss20FeedFormatter(feed);       

return new Atom10FeedFormatter(feed);
}

Note: if no parameters will be provided (i.e.: http://localhost/feed) the Feed method will be called with a NULL value.And here is what will glue everything together – the config file:

<configuration>
  <system.serviceModel>
    <services>
      <service name="FileChangeFeed.FileChangeFeedService">
        <endpoint address="http://localhost:8080/feed"
           binding="webHttpBinding"
           bindingConfiguration=""
           contract="FileChangeFeed.IFileChangeFeed"
           behaviorConfiguration="webBehavior" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="webBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
<configuration>

Note the endpoint behavior. As you can guess the feed can be published over any protocol, but if you’ll want to view the feed using standard RSS feed readers, it’s better to publish it over HTTP.As soon as you’ll start the application and the service will be published – put the base Uri (http://localhost:8080/feed) in IE’s address box and you’ll see a rendered RSS feed view.Have fun with RSS feeds and don’t be afraid to explore your possibilities.The source code can be found on my site.


				

Posted in C#, REST, Software, WCF | 1 Comment »

 
%d bloggers like this: