<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://scottonwriting.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Scott On Writing.NET : Web Services</title><link>http://scottonwriting.net/sowblog/archive/tags/Web+Services/default.aspx</link><description>Tags: Web Services</description><dc:language>en</dc:language><generator>CommunityServer 2007 (Build: 20423.869)</generator><item><title>Returning Dynamic Types from an Ajax Web Service Using C# 4.0</title><link>http://scottonwriting.net/sowblog/archive/2010/10/26/returning-dynamic-types-from-an-ajax-web-service-using-c-4-0.aspx</link><pubDate>Tue, 26 Oct 2010 02:40:12 GMT</pubDate><guid isPermaLink="false">2814ed8b-42a8-4dfe-b0b1-a7acb3e6d762:171098</guid><dc:creator>Scott Mitchell</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scottonwriting.net/sowblog/rsscomments.aspx?PostID=171098</wfw:commentRss><comments>http://scottonwriting.net/sowblog/archive/2010/10/26/returning-dynamic-types-from-an-ajax-web-service-using-c-4-0.aspx#comments</comments><description>&lt;p&gt;Over at &lt;a href="http://www.4guysfromrolla.com"&gt;4Guys&lt;/a&gt; I’m authoring a series of articles showing &lt;a href="http://www.4guysfromrolla.com/articles/102010-1.aspx"&gt;different techniques for accessing server-side data from client script&lt;/a&gt;. The most recent installment (&lt;a href="http://www.4guysfromrolla.com/articles/102710-1.aspx"&gt;Part 2&lt;/a&gt;) shows how to provide server-side data through the use of an Ajax Web Service and how to consume that data using either a proxy class created by the ASP.NET Ajax Library or by communicating with the Ajax Web Service directly using jQuery.&lt;/p&gt;  &lt;p&gt;When returning data from a service it’s not uncommon to create a specialized &lt;a href="http://en.wikipedia.org/wiki/Data_transfer_object"&gt;Data Transfer Object&lt;/a&gt; (or DTO), and in Part 2 I create two such DTO classes. Here’s the basic design pattern:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Create a DTO class that has properties that model the data you wan to return. For instance, the following DTO class can be used to transmit &lt;strong&gt;CategoryID&lt;/strong&gt;, &lt;strong&gt;CategoryName&lt;/strong&gt;, and &lt;strong&gt;Description&lt;/strong&gt; information about one or more categories.&lt;/li&gt;    &lt;pre class="brush: csharp;"&gt;public class CategoryDTO
{
    public int CategoryID { get; set; }
    public string CategoryName { get; set; }
    public string Description { get; set; }
}&lt;/pre&gt;

  &lt;li&gt;In the service, get the data of interest from your object layer. In the demo for this article series I use Linq-To-Sql as my data access layer and object model. Here is code from the Ajax Web Service’s &lt;strong&gt;GetCategories&lt;/strong&gt; method that retrieves information about the categories in the system:&lt;/li&gt;

  &lt;pre class="brush: csharp;"&gt;[WebMethod]
public CategoryDTO[] GetCategories()
{
    using (var dbContext = new NorthwindDataContext())
    {
        var results = from category in dbContext.Categories
                        orderby category.CategoryName
                        select category;

        ...
    }
}&lt;/pre&gt;

  &lt;li&gt;Now the results need to be mapped from the domain object to the DTO. This can be done manually or by using a library like &lt;a href="http://automapper.codeplex.com/"&gt;AutoMapper&lt;/a&gt;. In the above example, we would iterate through the results to create an array of &lt;strong&gt;CategoryDTO&lt;/strong&gt; objects, which is what would be returned.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you are using C# 4.0 you can choose to live in a looser-typed world. Rather than having the Ajax Web Service return a strongly-typed value (namely, an array of &lt;strong&gt;CategoryDTO&lt;/strong&gt; objects) you could instead opt to have a more ethereal return type – &lt;strong&gt;dynamic&lt;/strong&gt;! Having a return type of dynamic allows you to return an anonymous type, meaning you don’t need to create a DTO nor do you need to map the domain object to the DTO. Instead, you’d just create an anonymous type, like so:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;[WebMethod]
public dynamic GetCategories()
{
    using (var dbContext = new NorthwindDataContext())
    {
        var results = from category in dbContext.Categories
                        orderby category.CategoryName
                        select new
                        {
                            category.CategoryID,
                            category.CategoryName,
                            category.Description
                        };

        return results.ToArray();
    }
}&lt;/pre&gt;

&lt;p&gt;Note the &lt;strong&gt;dynamic&lt;/strong&gt; keyword as the method’s return type. Also note that &lt;strong&gt;results&lt;/strong&gt; is a query that returns an enumeration of anonymous types, each of which has three properties – &lt;strong&gt;CategoryID&lt;/strong&gt;, &lt;strong&gt;CategoryName&lt;/strong&gt;, and &lt;strong&gt;Description&lt;/strong&gt;. The call to the &lt;strong&gt;ToArray&lt;/strong&gt; method executes the query and returns the array of anonymous types as the method’s output. Because the anonymous type’s properties. The client-side script calling this method can work with the returned anonymous type using the exact same code as with the strongly-typed return type.&lt;/p&gt;

&lt;p&gt;Happy Programming!&lt;/p&gt;&lt;img src="http://scottonwriting.net/aggbug.aspx?PostID=171098" width="1" height="1"&gt;</description><category domain="http://scottonwriting.net/sowblog/archive/tags/ASP.NET+Talk/default.aspx">ASP.NET Talk</category><category domain="http://scottonwriting.net/sowblog/archive/tags/Web+Services/default.aspx">Web Services</category></item><item><title>Adding a RESTful Service to My Boggle Solver</title><link>http://scottonwriting.net/sowblog/archive/2010/09/11/adding-a-restful-service-to-my-boggle-solver.aspx</link><pubDate>Fri, 10 Sep 2010 22:47:20 GMT</pubDate><guid isPermaLink="false">2814ed8b-42a8-4dfe-b0b1-a7acb3e6d762:169410</guid><dc:creator>Scott Mitchell</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scottonwriting.net/sowblog/rsscomments.aspx?PostID=169410</wfw:commentRss><comments>http://scottonwriting.net/sowblog/archive/2010/09/11/adding-a-restful-service-to-my-boggle-solver.aspx#comments</comments><description>&lt;p align="center"&gt;&lt;font color="#ff0000" size="5"&gt;This blog post has been deprecated. Please see &lt;a href="http://www.4guysfromrolla.com/articles/112410-1.aspx"&gt;Updating My Online Boggle Solver Using jQuery Templates and WCF&lt;/a&gt; for an updated discussion on the solver service, the data it returns, and how to call it from a web page.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;My immediate and extended family enjoys playing games, and one of our favorites is Boggle. &lt;a href="http://en.wikipedia.org/wiki/Boggle"&gt;Boggle&lt;/a&gt; is a word game trademarked by Parker Brothers and Hasbro that involves several players trying to find as many words as they can in a 4x4 grid of letters. At the end of the game, players compare the words they found. During this comparison I've always wondered what words we may have missed. Was there some elusive 10-letter word that no one unearthed? Did we only discover 25 solutions when there were 200 or more?&lt;/p&gt;  &lt;p&gt;To answer these questions I created a Boggle solver web application (back in 2008) that prompts a user for the letters in the Boggle board and then recursively explores the board to locate (and display) all available solutions. This &lt;a href="http://fuzzylogicinc.net/Boggle/"&gt;Boggle solver&lt;/a&gt; is available online - &lt;a href="http://fuzzylogicinc.net/Boggle/"&gt;fuzzylogicinc.net/Boggle&lt;/a&gt;. My family uses it every time we get together and play Boggle. For more information on how it works and to get your hands on the code, check out my article, &lt;a href="http://www.4guysfromrolla.com/articles/040208-1.aspx"&gt;Creating an Online Boggle Solver&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Recently, I’ve been working on some projects that have involved creating &lt;a href="http://en.wikipedia.org/wiki/Representational_State_Transfer#RESTful_web_services"&gt;RESTful web services&lt;/a&gt; using &lt;a href="http://msdn.microsoft.com/en-us/netframework/aa663324.aspx"&gt;WCF&lt;/a&gt;. Being Friday, I decided to have a little fun and add a RESTful interface to the Boggle solver. This was actually quite easy to do and took all of 5 minutes.&lt;/p&gt;  &lt;h2&gt;Creating the Boggle Solver Service&lt;/h2&gt;  &lt;p&gt;I started by adding a new item to my website of type WCF Service, naming it &lt;strong&gt;Solver.svc&lt;/strong&gt;. This created three files:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Solver.scr &lt;/li&gt;    &lt;li&gt;ISolver.cs &lt;/li&gt;    &lt;li&gt;Solver.cs &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In the contract (&lt;strong&gt;ISolver.cs&lt;/strong&gt;) I added a single method, &lt;strong&gt;Solve&lt;/strong&gt;, that accepts two inputs: a string representing the board and a string indicating the minimum number of letters for a word to be considered a solution. (Boggle rules allow for words of three letters or more, but house rules only count words that are four letters or longer.) I then used the &lt;strong&gt;WebGet&lt;/strong&gt; attribute to indicate that the board and length input parameters would be specified via the querystring fields &lt;strong&gt;BoardID&lt;/strong&gt; and &lt;strong&gt;Length&lt;/strong&gt;, and that the resulting output should be formatted as &lt;a href="http://json.org/"&gt;JSON&lt;/a&gt;.&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;[ServiceContract]
public interface ISolver
{
    [OperationContract]
    [WebGet(UriTemplate = &amp;quot;?BoardID={board}&amp;amp;Length={length}&amp;quot;, ResponseFormat=WebMessageFormat.Json)]
    BoggleWordDTO[] Solve(string board, string length);
}&lt;/pre&gt;

&lt;p&gt;Note that the &lt;strong&gt;Solve&lt;/strong&gt; method returns an array of &lt;strong&gt;BoggleWordDTO&lt;/strong&gt; objects. This is a new class I created to represent the data to transmit from the service. This class has two properties:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Word&lt;/strong&gt; – a string value that represents a word found in the Boggle board, and &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Score&lt;/strong&gt; – the score for that solution. According to the official rules, three and four letter words are worth 1 point, five letter words are worth 2, six letter words worth 3, seven letter words worth 5, and eight letter words and longer worth 11. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;strong&gt;Solve&lt;/strong&gt; method implementation (&lt;strong&gt;Solver.cs&lt;/strong&gt;) is pretty straightforward. It starts with a bit of error checking to ensure that the passed in board and letter information is kosher. Next, it creates a &lt;strong&gt;BoggleBoard&lt;/strong&gt; object, specifying the minimum number of letters for a solution and the board contents. Then the BoggleBoard object’s &lt;strong&gt;Solve&lt;/strong&gt; method is invoked, which performs the recursion and computes the set of solutions (as an object of type &lt;strong&gt;BoggleWordList&lt;/strong&gt;). The solutions are then converted into an array of &lt;strong&gt;BoggleWordDTO&lt;/strong&gt; objects, which is then returned to the client.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public BoggleWordDTO[] Solve(string board, string length)
{
    ...

    // Create the BoggleBoard
    BoggleBoard bb = new BoggleBoard(
                        letters,
                        board[0].ToString(), ..., board[15].ToString()
                    );

    // Solve the Boggle board
    var solutions = bb.Solve();

    // Populate and return an array of BoggleWordDTO objects
    return solutions
                .Select(s =&amp;gt; new BoggleWordDTO()
                {
                    Word = s.Word,
                        Score = s.Score
                })
                .ToArray();
}&lt;/pre&gt;

&lt;p&gt;Because the service is configured to return the data using JSON, the results are serialized into a JSON array.&lt;/p&gt;

&lt;p&gt;In addition to creating the Solver-related files and writing the code I noted, I also had to add &lt;strong&gt;&amp;lt;system.serviceModel&amp;gt;&lt;/strong&gt; configuration to &lt;strong&gt;Web.config&lt;/strong&gt; to permit HTTP access to the service &lt;strike&gt;and to enable ASP.NET compatibility. The reason I had to enable ASP.NET compatibility is because the dictionary used by the solver is a text file stored on disk, and the solver gets the path to that text file using &lt;strong&gt;Server.MapPath&lt;/strong&gt; (namely, &lt;strong&gt;HttpContext.Current.Server.MapPath(“…”)&lt;/strong&gt;). Without ASP.NET compatibility, &lt;strong&gt;HttpContext.Current&lt;/strong&gt; is null when the service attempts to solve and then the call to &lt;strong&gt;Server.MapPath&lt;/strong&gt; blows up.&lt;/strike&gt; Also, I had to specify the &lt;strong&gt;Factory&lt;/strong&gt; attribute in the &lt;strong&gt;&amp;lt;%@ ServiceHost %&amp;gt; &lt;/strong&gt;directive of the &lt;strong&gt;Solver.svc&lt;/strong&gt; file. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;[UPDATE: 2010-09-10]&lt;/strong&gt; &lt;a href="http://allben.net/"&gt;Ben Amada&lt;/a&gt; posted a helpful comment pointing me to the existence of the &lt;strong&gt;HostingEnvironment.MapPath&lt;/strong&gt; method, which does the same work as &lt;strong&gt;Server.MapPath&lt;/strong&gt; but doesn’t require an &lt;strong&gt;HttpContext&lt;/strong&gt; object. I updated this code accordingly. I also updated the code that cached the dictionary in memory, replacing the use of &lt;strong&gt;HttpContext.Current.Cache&lt;/strong&gt; with &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.httpruntime.cache.aspx"&gt;HttpRuntime.Cache&lt;/a&gt;, which I &lt;a href="http://weblogs.asp.net/pjohnson/archive/2006/02/06/437559.aspx"&gt;probably should have been using all along&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt;. The code has been updated. Thanks, Ben!&lt;/p&gt;

&lt;h2&gt;Using the Boggle Solver Service&lt;/h2&gt;

&lt;p&gt;To use the service, just point your browser (or your code/script) to:&amp;#160; &lt;strong&gt;&lt;a href="http://fuzzylogicinc.net/Boggle/Solver.svc?BoardID=board&amp;amp;Length=length"&gt;http://fuzzylogicinc.net/Boggle/Solver.svc?BoardID=&lt;em&gt;board&lt;/em&gt;&amp;amp;Length=&lt;em&gt;length&lt;/em&gt;&lt;/a&gt;&lt;/strong&gt;. The &lt;em&gt;board&lt;/em&gt; value should be entered as a string of the characters in the Boggle board, starting from the upper left corner and reading to the right and down. For example, if you had the board:&lt;/p&gt;

&lt;pre&gt;r e i b
t m f w
i r a e
r h s t &lt;/pre&gt;

&lt;p&gt;You would use a &lt;em&gt;board&lt;/em&gt; value of &lt;strong&gt;reibtmfwiraerhst&lt;/strong&gt;. &lt;em&gt;letter&lt;/em&gt; should be a number between 3 and 6, inclusive.&lt;/p&gt;

&lt;p&gt;So, to find all solutions to the above board that are four or more letters, you’d visit: &lt;a title="http://fuzzylogicinc.net/Boggle/Solver.svc?BoardID=reibtmfwiraerhst&amp;amp;Length=4" href="http://fuzzylogicinc.net/Boggle/Solver.svc?BoardID=reibtmfwiraerhst&amp;amp;Length=4"&gt;http://fuzzylogicinc.net/Boggle/Solver.svc?BoardID=reibtmfwiraerhst&amp;amp;Length=4&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Doing so would return the following (abbreviated) JSON:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;[{&amp;quot;Score&amp;quot;:1,&amp;quot;Word&amp;quot;:&amp;quot;amir&amp;quot;},{&amp;quot;Score&amp;quot;:2,&amp;quot;Word&amp;quot;:&amp;quot;amirs&amp;quot;},{&amp;quot;Score&amp;quot;:1,&amp;quot;Word&amp;quot;:&amp;quot;awes&amp;quot;},{&amp;quot;Score&amp;quot;:1,&amp;quot;Word&amp;quot;:&amp;quot;bier&amp;quot;},{&amp;quot;Score&amp;quot;:1,&amp;quot;Word&amp;quot;:&amp;quot;ears&amp;quot;},{&amp;quot;Score&amp;quot;:1,&amp;quot;Word&amp;quot;:&amp;quot;east&amp;quot;},...]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The above JSON represents an array of objects, where each object has two properties, &lt;strong&gt;Score&lt;/strong&gt; and &lt;strong&gt;Word&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So how can this service be used? Well, with a bit of JavaScript you can call the service from a browser and display the results dynamically. I’ve included a rudimentary example in the download (which you can find at the end of this blog post) that prompts the user to enter the 16 characters for the board and the minimum number of letters. It then uses &lt;a href="http://jquery.com/"&gt;jQuery&lt;/a&gt;’s &lt;a href="http://api.jquery.com/jQuery.getJSON/"&gt;&lt;strong&gt;getJSON&lt;/strong&gt; function&lt;/a&gt; to make a call to the service and get the data back. The JSON array is then enumerated and a series of list items are constructed, showing each solution in a bulleted list.&lt;/p&gt;

&lt;p&gt;Here is the web page when you visit it and enter a boggle board and the minimum number of letters (but before you click the “Find All Words!” button.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://nbaweblog.com/images/sowblog/BoggleBoard2_0C860A56.gif"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="BoggleBoard2" border="0" alt="BoggleBoard2" src="http://nbaweblog.com/images/sowblog/BoggleBoard2_thumb_209F26DF.gif" width="547" height="312" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Clicking the “Find All Words!” button executes the following jQuery script:&lt;/p&gt;

&lt;pre class="brush: js;"&gt;$.getJSON(
    &amp;quot;Solver.svc&amp;quot;,
    {
        &amp;quot;BoardID&amp;quot;: $(&amp;quot;#board&amp;quot;).val(),
        &amp;quot;Length&amp;quot;: $(&amp;quot;#length&amp;quot;).val()
    },
    function (words) {
        var output = &amp;quot;No solutions exists!&amp;quot;;

        if (words.length &amp;gt; 0) {
            output = &amp;quot;&amp;lt;h2&amp;gt;&amp;quot; + words.length + &amp;quot; Solutions!&amp;lt;/h2&amp;gt;&amp;lt;ul&amp;gt;&amp;quot;;

            var score = 0;

            $.each(words, function (index, word) {
                score += word.Score;
                output += &amp;quot;&amp;lt;li&amp;gt;&amp;quot; + word.Word + &amp;quot; (&amp;quot; + word.Score + &amp;quot; points)&amp;lt;/li&amp;gt;&amp;quot;;
            });

            output += &amp;quot;&amp;lt;/ul&amp;gt;&amp;lt;p&amp;gt;Total score = &amp;quot; + score + &amp;quot; points!&amp;lt;/p&amp;gt;&amp;quot;;
        }

        $(&amp;quot;#solutions&amp;quot;).html(output);
    }
);&lt;/pre&gt;

&lt;p&gt;Note that the above script calls the &lt;strong&gt;Solver.svc&lt;/strong&gt; service passing in the BoardID and Length querystring parameters. The textbox where the user enters the board has an &lt;strong&gt;id&lt;/strong&gt; of &lt;strong&gt;board&lt;/strong&gt; while the minimum letter drop-down list has an &lt;strong&gt;id&lt;/strong&gt; of &lt;strong&gt;length&lt;/strong&gt;. The function defined in the call is what is executed when the result comes back successfully. Here, the jQuery &lt;a href="http://api.jquery.com/each/"&gt;&lt;strong&gt;each &lt;/strong&gt;function&lt;/a&gt; is used to enumerate the array and build up a string of HTML in a variable named &lt;strong&gt;output&lt;/strong&gt; that produces a bulleted list of solutions. The total number of solutions and total number of points is also included in &lt;strong&gt;output&lt;/strong&gt;. Finally, the contents of &lt;strong&gt;output&lt;/strong&gt; are dumped to a &lt;strong&gt;&amp;lt;div&amp;gt;&lt;/strong&gt; on the page with an &lt;strong&gt;id&lt;/strong&gt; of &lt;strong&gt;solutions&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here’s the page after clicking the “Find All Words!” button. Nothing fancy, of course, and not nearly as useful or eye-pleasing as &lt;a href="http://fuzzylogicinc.net/Boggle/EnterBoard.aspx?BoardID=reibtmfwiraerhst&amp;amp;Length=4"&gt;the website’s results page&lt;/a&gt;, but it does illustrate one way you can use the Boggle &lt;strong&gt;Solver.svc&lt;/strong&gt; service.&lt;/p&gt;

&lt;p align="center"&gt;&lt;a href="http://nbaweblog.com/images/sowblog/BoggleBoard3_71D96E3C.gif"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="BoggleBoard3" border="0" alt="BoggleBoard3" src="http://nbaweblog.com/images/sowblog/BoggleBoard3_thumb_1EEE5B0B.gif" width="353" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;Download the Code!&lt;/h2&gt;

&lt;p&gt;You can download the complete Boggle solver engine, web application, and WCF RESTful service from &lt;a title="http://aspnet.4guysfromrolla.com/code/BoggleSolver.zip" href="http://aspnet.4guysfromrolla.com/code/BoggleSolver.zip"&gt;http://aspnet.4guysfromrolla.com/code/BoggleSolver.zip&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Happy Programming, and Happy Boggling!&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;&lt;img src="http://scottonwriting.net/aggbug.aspx?PostID=169410" width="1" height="1"&gt;</description><category domain="http://scottonwriting.net/sowblog/archive/tags/ASP.NET+Talk/default.aspx">ASP.NET Talk</category><category domain="http://scottonwriting.net/sowblog/archive/tags/Miscellaneous/default.aspx">Miscellaneous</category><category domain="http://scottonwriting.net/sowblog/archive/tags/Web+Services/default.aspx">Web Services</category><category domain="http://scottonwriting.net/sowblog/archive/tags/jQuery/default.aspx">jQuery</category></item><item><title>Fixing "The Following Add-Ins Failed to Load" Error in Visual Studio .NET</title><link>http://scottonwriting.net/sowblog/archive/2005/09/19/163110.aspx</link><pubDate>Tue, 20 Sep 2005 01:35:00 GMT</pubDate><guid isPermaLink="false">2814ed8b-42a8-4dfe-b0b1-a7acb3e6d762:163110</guid><dc:creator>Scott Mitchell</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scottonwriting.net/sowblog/rsscomments.aspx?PostID=163110</wfw:commentRss><comments>http://scottonwriting.net/sowblog/archive/2005/09/19/163110.aspx#comments</comments><description>&lt;p&gt;I am giving a talk on Web Services this week and one technology I discuss in virtually every Web Services talk is the &lt;a href="http://msdn.microsoft.com/webservices/webservices/building/wse/default.aspx"&gt;Web Services Enhancement (WSE) Toolkit&lt;/a&gt;.  One of the nice things about the WSE Toolkit is that it integrates with Visual Studio .NET - right-click on the Web Service or client project and there's a WSE 2.0 Settings option in the context menu that brings up a GUI to edit the WSE-related settings.  However, in running through the talk/demo code today, I noticed that my copy of VS.NET on my laptop wasn't displaying the option in the GUI.&lt;/p&gt;
&lt;p&gt;My first attempt at fixing this was to simply uninstall and reinstall the WSE Toolkit.  Upon restarting VS.NET after this process, I got a dialog box with the warning, “The Following Add-Ins Failed to Load - WSE 2.0.”  Urg.  I did a bit of searching and discovered that one way to fix this was to “repair” the VS.NET installation.  So, off I went to the Add/Remove New Programs screen and went to the VS.NET installation screen and clicked on the Repair/Reinstall option.  This prompted me for the VS.NET CDs and, about 20 minutes later, wrapped up doing whatever in the world it was doing.&lt;/p&gt;
&lt;p&gt;Fortunately, this fixed the problem for me.  I have no idea what the problem was, exactly, but opting to repair VS.NET is what ended up working for me.  Hope this helps someone else in a similar situation.  For those more familiar with VS.NET Add-In specifics, any guesses/ideas as to what the problem was and, perhaps, a more direct, quicker workaround?&lt;/p&gt;&lt;img src="http://scottonwriting.net/aggbug.aspx?PostID=163110" width="1" height="1"&gt;</description><category domain="http://scottonwriting.net/sowblog/archive/tags/ASP.NET+Talk/default.aspx">ASP.NET Talk</category><category domain="http://scottonwriting.net/sowblog/archive/tags/Web+Services/default.aspx">Web Services</category></item><item><title>TONIGHT: What Are .NET Web Services? Talk</title><link>http://scottonwriting.net/sowblog/archive/2005/07/14/163094.aspx</link><pubDate>Thu, 14 Jul 2005 14:54:00 GMT</pubDate><guid isPermaLink="false">2814ed8b-42a8-4dfe-b0b1-a7acb3e6d762:163094</guid><dc:creator>Scott Mitchell</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scottonwriting.net/sowblog/rsscomments.aspx?PostID=163094</wfw:commentRss><comments>http://scottonwriting.net/sowblog/archive/2005/07/14/163094.aspx#comments</comments><description>&lt;p&gt;Tonight I will be presenting a talk titled &lt;a href="http://datawebcontrols.com/classes/WS.zip"&gt;&lt;em&gt;What are Web Services?&lt;/em&gt;&lt;/a&gt; for the &lt;a href="http://www.sandiegodotnet.com/SDNETUG/DesktopDefault.aspx?tabid=24"&gt;San Diego .NET User Group Beginner's SIG&lt;/a&gt; (a synopsis of the talk is given at the end of this post).  The talk starts at 6:30 and is held in an office in Del Mar, just north of the 56 and just east of the 5.  In addition to hearing me babble on about Web Services for an hour and change, there will be &lt;font color="#ff1493"&gt;&lt;strong&gt;&lt;em&gt;free pizza&lt;/em&gt;&lt;/strong&gt;&lt;/font&gt;!!!  Hope to see you there!&lt;/p&gt;
&lt;blockquote dir="ltr" style="MARGIN-RIGHT: 0px"&gt;
&lt;p&gt;This talk will examine the fundamentals of Web services from a beginner's perspective, focusing on the goals of Web services and common uses of Web services in industry today. It Includes a high-level look at the core Web service standards, along with live demos illustrating how to create a Web service and client application using Visual Studio .NET.&lt;/p&gt;&lt;/blockquote&gt;&lt;img src="http://scottonwriting.net/aggbug.aspx?PostID=163094" width="1" height="1"&gt;</description><category domain="http://scottonwriting.net/sowblog/archive/tags/Web+Services/default.aspx">Web Services</category></item><item><title>Viewing WSE Trace Files</title><link>http://scottonwriting.net/sowblog/archive/2004/12/03/163023.aspx</link><pubDate>Fri, 03 Dec 2004 20:13:00 GMT</pubDate><guid isPermaLink="false">2814ed8b-42a8-4dfe-b0b1-a7acb3e6d762:163023</guid><dc:creator>Scott Mitchell</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scottonwriting.net/sowblog/rsscomments.aspx?PostID=163023</wfw:commentRss><comments>http://scottonwriting.net/sowblog/archive/2004/12/03/163023.aspx#comments</comments><description>&lt;p&gt;One of the neat features of Microsoft's &lt;a href="http://msdn.microsoft.com/webservices/building/wse/default.aspx"&gt;WSE Toolkit&lt;/a&gt; is that with the click of a button you can have all incoming and outgoing SOAP messages from a client or service recorded in trace files.  These files, named by default &lt;font face="Courier New"&gt;InputTrace.webinfo&lt;/font&gt; and &lt;font face="Courier New"&gt;OutputTrace.webinfo&lt;/font&gt;, can be helpful for debugging or for gaining a deeper understanding as to the actual XML being scurried back and forth between a client and a Web service.  One thing that's always irked me, though, is that these trace files are simply appended to with each run.  This is fine and good, I guess, but it makes it hard to pick through these logs.&lt;/p&gt;
&lt;p&gt;Every time I introduce WSE to my Web Services .NET students, I show them the tracing features, and have to sludge through opening the files in UltraEdit32, or Internet Explorer, and paging through the XML and finding the incoming and outgoing messages for the example we had just completed.  Well, I decided enough was enough, so I spent this morning whipping up a simply WinForms application that allows you to load in trace files and view individual messages from them, one at a time, as the following screenshot illustrates (in the screnshot I am viewing just Message #9):&lt;/p&gt;
&lt;p align="center"&gt;&lt;img height="268" src="http://www.datawebcontrols.com/images/wseTraceViewer0.ss.gif" width="500" /&gt;&lt;/p&gt;
&lt;p&gt;I also made it so that you can view the input &lt;em&gt;and&lt;/em&gt; output XML for a given message number, as shown in the following screenshot:&lt;/p&gt;
&lt;p align="center"&gt;&lt;img src="http://www.datawebcontrols.com/images/wseTraceViewer.ss.gif" /&gt;&lt;/p&gt;
&lt;p&gt;If you'd like, you can &lt;a href="http://scottonwriting.net/sowblog/CodeProjectFiles/WSETraceViewer.zip"&gt;download the application and complete source code&lt;/a&gt; (C#).  I have to give a big caveat here, though: I am not an experienced WinForms developer by any stretch of the imagination, so you may find glaring UI errors, terrible design, and offensive source code.  Be forewarned.  I learned a lot of new things today and played around with things like isolated storage and resizing WinForm controls... things I've done zero times before, so the code may be littered with mistakes.  Also, I do zero exception handling, so a missing file, or invalid permissions, or malformatted XML, and &lt;strong&gt;kablamo&lt;/strong&gt;, the app's gonna bomb out on you.&lt;/p&gt;
&lt;p&gt;Ok, enough of a caveat.  Enjoy the program!&lt;/p&gt;&lt;img src="http://scottonwriting.net/aggbug.aspx?PostID=163023" width="1" height="1"&gt;</description><category domain="http://scottonwriting.net/sowblog/archive/tags/Miscellaneous/default.aspx">Miscellaneous</category><category domain="http://scottonwriting.net/sowblog/archive/tags/Web+Services/default.aspx">Web Services</category></item><item><title>Cryptic WSE 2.0 Error (WSE032 "configuration error" and System.Net.Dns.GetHostName())</title><link>http://scottonwriting.net/sowblog/archive/2004/12/02/163022.aspx</link><pubDate>Fri, 03 Dec 2004 02:34:00 GMT</pubDate><guid isPermaLink="false">2814ed8b-42a8-4dfe-b0b1-a7acb3e6d762:163022</guid><dc:creator>Scott Mitchell</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scottonwriting.net/sowblog/rsscomments.aspx?PostID=163022</wfw:commentRss><comments>http://scottonwriting.net/sowblog/archive/2004/12/02/163022.aspx#comments</comments><description>&lt;p&gt;While I was teaching my .NET Web Services class tonight I stumbled upon an esoteric error with WSE 2.0 that I had not encountered before - an error that ruined two demos of mine.  I had tried the demos literally 15 minutes before class and theyh worked great.  When I had a full classroom, though, it crapped out.  The error message I got was the standard WSE032, saying:&lt;/p&gt;
&lt;blockquote dir="ltr" style="MARGIN-RIGHT: 0px"&gt;
&lt;p&gt;An unhandled exception of type 'System.Configuration.ConfigurationException' occured in microsoft.web.services2.dll&lt;/p&gt;
&lt;p&gt;Additional information: WSE032: There was an error loading the microsoft.web.services2 configuration section&lt;/p&gt;&lt;/blockquote&gt;
&lt;p dir="ltr"&gt;This is a pretty common error message when something has gone awry in WSE.  For example, if you are using UsernameToken authentication, but mistype any values in the Web.config file you'll get this error.  What was a bit perplexing was that, (a) the demos had worked earlier, and (b) the stack trace of the error message referred to a problem with &lt;font face="Courier New"&gt;System.Net.Dns.GetHostName()&lt;/font&gt;.  As I said, my demos bombed out, but afterwards I did a quick search on Google and found this blog entry: &lt;a href="http://weblogs.asp.net/israelio/archive/2004/10/03/237236.aspx"&gt;WSE 2.0 (sp1 &amp;amp; earlier) - The mistory [sic] of error code WSE032&lt;/a&gt;.&lt;/p&gt;
&lt;p dir="ltr"&gt;This blog entry had a fix for my problem.  It appears that WSE uses the &lt;font face="Courier New"&gt;GetHostName()&lt;/font&gt; method, and this caused some problems, perhaps because my computer's wireless connection died, or my DNS entries timed out, or something.  Anywho, the solution - which worked for me - was to add a line to the HOSTS file in &lt;font face="Courier New"&gt;C:\WINDOWS\system32\drivers\etc&lt;/font&gt;.  This did the trick.  Probably the most esoteric bug I've faced in my experiences with Web services.&lt;/p&gt;&lt;img src="http://scottonwriting.net/aggbug.aspx?PostID=163022" width="1" height="1"&gt;</description><category domain="http://scottonwriting.net/sowblog/archive/tags/ASP.NET+Talk/default.aspx">ASP.NET Talk</category><category domain="http://scottonwriting.net/sowblog/archive/tags/Web+Services/default.aspx">Web Services</category></item><item><title>Random (Perhaps Outdated) Web Service Tip for the Weekend</title><link>http://scottonwriting.net/sowblog/archive/2004/11/06/163010.aspx</link><pubDate>Sun, 07 Nov 2004 02:07:00 GMT</pubDate><guid isPermaLink="false">2814ed8b-42a8-4dfe-b0b1-a7acb3e6d762:163010</guid><dc:creator>Scott Mitchell</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scottonwriting.net/sowblog/rsscomments.aspx?PostID=163010</wfw:commentRss><comments>http://scottonwriting.net/sowblog/archive/2004/11/06/163010.aspx#comments</comments><description>&lt;p&gt;With the Web Service Enhancement (WSE) Toolkit it is very easy to view incoming/outgoing SOAP requests - just check the “Enable Message Trace“ option in the option in the Diagnostics tab of the WSE Toolkit, and off you go.  But prior to the WSE Toolkit, providing such essential debugging information was, unfortunately, not as straightforward or easy.  Older books on Web services, for example, talk about using the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=C943C0DD-CEEC-4088-9753-86F052EC8450&amp;amp;displaylang=en"&gt;SOAP Toolkit&lt;/a&gt;, from which you can create a SOAP proxy to record the incoming and outgoing SOAP messages.  However, there's a much easier way, as Web service-guru &lt;a href="http://msdn.microsoft.com/asp.net/community/authors/mlb/default.aspx"&gt;Michele Leroux-Bustamante&lt;/a&gt; showed me 14 months ago, almost to the day: in a Web service method, add th following code to save the incoming SOAP content:&lt;/p&gt;
&lt;blockquote dir="ltr" style="MARGIN-RIGHT: 0px"&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;HttpContext.Current.Request.SaveAs(&lt;em&gt;filePathToSaveSOAPData, &lt;/em&gt;true);&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;This will dump the incoming request to a file, including the headers (set the second parameter to False to omit the headers).  Unfortunately this raw text output is not nicely indented like the WSE Toolkit output, but it provides a simple way to quickly inspect the incoming SOAP requests from the Web service.&lt;/p&gt;
&lt;p&gt;Speaking of Michele, she'll be speaking at &lt;a href="http://devconnections.com/devconnections/asp/"&gt;the ASP.NET Connections conference&lt;/a&gt;, which starts up with pre-session tracks tomorrow and continues throughout all next week.  I mention this because I'll be there, too.  Well, not inside the conference, per se, but in Vegas, at the Mandalay Bay resort.  My wife's company is sending her, so I decided to tote along as a bit of a vacation (for myself).  So, while my wife's toiling away in the conference sessions, learning the latest and greatest information about ASP.NET 1.x and 2.0, I'll be hitting the blackjack tables!  (More accurately I'll likely be holed up in the hotel room, working on my two upcoming MSDN articles, but I promise to at least periodically fantasize about striking it rich with lady luck.)&lt;/p&gt;&lt;img src="http://scottonwriting.net/aggbug.aspx?PostID=163010" width="1" height="1"&gt;</description><category domain="http://scottonwriting.net/sowblog/archive/tags/Web+Services/default.aspx">Web Services</category></item><item><title>Sample Chapter of my .NET Web Services DVD</title><link>http://scottonwriting.net/sowblog/archive/2004/10/12/163000.aspx</link><pubDate>Tue, 12 Oct 2004 13:22:00 GMT</pubDate><guid isPermaLink="false">2814ed8b-42a8-4dfe-b0b1-a7acb3e6d762:163000</guid><dc:creator>Scott Mitchell</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scottonwriting.net/sowblog/rsscomments.aspx?PostID=163000</wfw:commentRss><comments>http://scottonwriting.net/sowblog/archive/2004/10/12/163000.aspx#comments</comments><description>&lt;img height="1" src="http://datawebcontrols.com/Tracker/Track.aspx?code=20041012" width="1" align="right" /&gt; 
&lt;p&gt;A few months ago &lt;a href="http://scottonwriting.net/sowblog/posts/1732.aspx"&gt;I announced the release of a training DVD&lt;/a&gt; of mine, &lt;em&gt;&lt;a href="http://dvpress.com/ecom/DVDBooks/PRODUCTDETAILST.ASPX?PNO=32"&gt;Beginners .NET XML Web Services 2004&lt;/a&gt;&lt;/em&gt;.  This two-disc DVD covers Web Services from the ground up, showing how to create and consume Web services using Visual Studio .NET 2003 using both VB.NET and C# examples.  In addition to covering the core features of Web Services - SOAP, XML serialization, WSDL, proxy classes, etc. - the DVD also explores the Web Service Enhancements (WSE), both from a high-level (Chapter 12), as well as two specific examples: UsernameToken authentication (Chapter 13) and sending attachments with DIME and WS-Attachments (Chapter 14).&lt;/p&gt;
&lt;p&gt;If you are interested in learning more about this DVD, you can check out Chapter 14 in its entirety (all 30+ minutes), which is available along with some other sample chapters from DVPress's training DVDs at &lt;a href="http://dvpress.com/ecom/Downloads/Sample_Clips.aspx"&gt;http://dvpress.com/ecom/Downloads/Sample_Clips.aspx&lt;/a&gt;.  &lt;/p&gt;
&lt;p&gt;One downside with the sample chapter is that in certain areas I refer to figures.  Some are flashed up on the screen, but some are not.  These figures - along with the complete source code for the projects I demoed - are all available on the DVDs.  Speaking of which, if you enjoy the sample chapter, consider picking up a copy of the DVD, which can be purchased through &lt;a href="http://dvpress.com/ecom/DVDBooks/PRODUCTDETAILST.ASPX?PNO=32"&gt;DVPress's website&lt;/a&gt; (they accept PayPal) or &lt;a href="http://www.amazon.com/exec/obidos/ASIN/B0002AHVPA/4guysfromrollaco"&gt;Amazon.com&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://scottonwriting.net/aggbug.aspx?PostID=163000" width="1" height="1"&gt;</description><category domain="http://scottonwriting.net/sowblog/archive/tags/ASP.NET+Talk/default.aspx">ASP.NET Talk</category><category domain="http://scottonwriting.net/sowblog/archive/tags/Web+Services/default.aspx">Web Services</category></item><item><title>Is There Anything More Self-Conscious than Watching Yourself?</title><link>http://scottonwriting.net/sowblog/archive/2004/08/12/162979.aspx</link><pubDate>Thu, 12 Aug 2004 13:16:00 GMT</pubDate><guid isPermaLink="false">2814ed8b-42a8-4dfe-b0b1-a7acb3e6d762:162979</guid><dc:creator>Scott Mitchell</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scottonwriting.net/sowblog/rsscomments.aspx?PostID=162979</wfw:commentRss><comments>http://scottonwriting.net/sowblog/archive/2004/08/12/162979.aspx#comments</comments><description>&lt;p&gt;My latest “book” is out, but this time it's not a book - it's a DVD.  About two and a half months ago I started talking with &lt;a href="http://dvpress.com/"&gt;DVPress&lt;/a&gt;, a company that makes technical training DVDs, and decided to participate in creating a DVD targetted toward those interested in learning the fundamentals of .NET Web Services.  I flew out to Houston at the end of May, and spent two days filming the seven or so hours of training that's on the two-disc DVD.  Yesterday I received the 20 author's copies and, naturally, sat down to watch myself.  The verdict?  I don't like the way my voice sounds (although I already knew that).&lt;/p&gt;
&lt;p&gt;Anywho, if you are interested in learning about .NET Web services, or know someone who is, or just want to own a DVD where yours truly is sitting there droning on for seven hours, you can pick up a copy of the DVD at Amazon.com: &lt;a href="http://www.amazon.com/exec/obidos/ASIN/B0002AHVPA/4guysfromrollaco"&gt;&lt;em&gt;Beginner's .NET XML Web Services&lt;/em&gt;&lt;/a&gt;&lt;em&gt; &lt;/em&gt;($29.95, qualified for free shipping).  The training covers the basics of Web services, looks at creating and consuming Web services with Visual Studio .NET, explores the SOAP and WSDL standards, and dives into the Web Service Enhancements, showing demos on both UsernameToken authentication and sending / receiving attachments with DIME and WS-Attachments.&lt;/p&gt;
&lt;p&gt;Funny side story from the days of filming: the studio is in an office building, and during my filming DVPress was expanding their office space into the neighboring suite.  In the other suite were a team of handy-men painting, cleaning, etc.  At one point, I'm in the middle of a chapter - the lights are off, save a set of bright lights on me, there's a camera and a cameraman filming, but despite this, a handyman quietly opens the door and walks into the room.  He walks behind the camera, over to the side and parallel with me, about six feet away from me (still off-camera, though).  The whole time I'm still looking in the camera, delivering the lesson... well, he starts painting a window sill, and he does so half turned so that while he's painting, he's watching me with this quizical look on his face.  Very surreal.&lt;/p&gt;&lt;img src="http://scottonwriting.net/aggbug.aspx?PostID=162979" width="1" height="1"&gt;</description><category domain="http://scottonwriting.net/sowblog/archive/tags/ASP.NET+Talk/default.aspx">ASP.NET Talk</category><category domain="http://scottonwriting.net/sowblog/archive/tags/Web+Services/default.aspx">Web Services</category></item><item><title>New Article on UsernameToken Authentication with the WSE 2.0 Toolkit</title><link>http://scottonwriting.net/sowblog/archive/2004/07/14/162964.aspx</link><pubDate>Wed, 14 Jul 2004 15:19:00 GMT</pubDate><guid isPermaLink="false">2814ed8b-42a8-4dfe-b0b1-a7acb3e6d762:162964</guid><dc:creator>Scott Mitchell</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scottonwriting.net/sowblog/rsscomments.aspx?PostID=162964</wfw:commentRss><comments>http://scottonwriting.net/sowblog/archive/2004/07/14/162964.aspx#comments</comments><description>&lt;p&gt;The &lt;a href="http://aspnet.4guysfromrolla.com/articles/071404-1.aspx"&gt;latest 4Guys article&lt;/a&gt; was published today, and looks at implementing UsernameToken authentication using the WSE 2.0 Toolkit.  In an &lt;a href="http://aspnet.4guysfromrolla.com/articles/063004-1.aspx"&gt;earlier article&lt;/a&gt; I wrote about the Web Service Enhancements (WSE), a set of extended Web service standards defined to help businesses implement common Web service needs not addressed by the core standards (such as security and messaging).  Anywho, Microsoft has been kind enough to create a free toolkit to assist developers in implementing the WSE standards.  This toolkit, called the &lt;a href="http://msdn.microsoft.com/webservices/building/wse/default.aspx"&gt;WSE 2.0 Toolkit&lt;/a&gt;, was officially RTMed back at TechEd this year (which &lt;a href="http://scottonwriting.net/sowblog/posts/1304.aspx"&gt;I blogged about&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;The main bulk of the WSE 2.0 standards address security standards.  Using WSE, one can implement secure Web services using industry-defined standards.  One of the security-related standards for WSE is the UsernameToken authentication standard, which spells out how a client can send along a username and password to a Web service for purposes of authentication.  This latest 4Guys article - available at &lt;a href="http://aspnet.4guysfromrolla.com/articles/071404-1.aspx"&gt;http://aspnet.4guysfromrolla.com/articles/071404-1.aspx&lt;/a&gt; - shows how easy it is to implement this standard using the WSE 2.0 Toolkit.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;This 4Guys article is the ninth part in an ongoing series titled &lt;a href="http://aspnet.4guysfromrolla.com/articles/100803-1.aspx"&gt;An Extensive Examination of Web Services&lt;/a&gt;...&lt;/em&gt;&lt;/p&gt;&lt;img src="http://scottonwriting.net/aggbug.aspx?PostID=162964" width="1" height="1"&gt;</description><category domain="http://scottonwriting.net/sowblog/archive/tags/Miscellaneous/default.aspx">Miscellaneous</category><category domain="http://scottonwriting.net/sowblog/archive/tags/Web+Services/default.aspx">Web Services</category></item></channel></rss>