<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Aaron Lerch &#187; web services</title>
	<atom:link href="http://www.aaronlerch.com/blog/category/web-services/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.aaronlerch.com/blog</link>
	<description></description>
	<lastBuildDate>Wed, 10 Mar 2010 12:45:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Unifying Web &quot;Sites&quot; and Web Services with the ASP.NET MVC Framework</title>
		<link>http://www.aaronlerch.com/blog/2008/01/01/unifying-web-sites-and-web-services-with-the-aspnet-mvc-framework/</link>
		<comments>http://www.aaronlerch.com/blog/2008/01/01/unifying-web-sites-and-web-services-with-the-aspnet-mvc-framework/#comments</comments>
		<pubDate>Wed, 02 Jan 2008 03:10:53 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://www.aaronlerch.com/blog/2008/01/01/unifying-web-sites-and-web-services-with-the-aspnet-mvc-framework/</guid>
		<description><![CDATA[(For those who&#8217;d rather just download the code, the link is at the end.)
Lately I&#8217;ve been delving into the ASP.NET MVC framework, the timing of which has been interesting as I am about to finish reading RESTful Web Services by Leonard Richardson and Sam Ruby. It&#8217;s an excellent book that I&#8217;d highly recommend to anybody [...]]]></description>
			<content:encoded><![CDATA[<p>(For those who&#8217;d rather just download the code, the link is at the end.)</p>
<p>Lately I&#8217;ve been delving into the <a href="http://weblogs.asp.net/scottgu/archive/2007/10/14/asp-net-mvc-framework.aspx">ASP.NET MVC framework</a>, the timing of which has been interesting as I am about to finish reading <a href="http://www.amazon.com/RESTful-Web-Services-Leonard-Richardson/dp/0596529260">RESTful Web Services</a> by Leonard Richardson and Sam Ruby. It&#8217;s an excellent book that I&#8217;d highly recommend to anybody designing and creating services for the web, or just interested in it.</p>
<p>This quote from the book description on Amazon.com succinctly describes what&#8217;s been floating around in my head for a while:</p>
<blockquote><p><em>You&#8217;ve built web sites that can be used by humans. But can you also build web sites that are usable by machines?</em> That&#8217;s where the future lies, and that&#8217;s what RESTful Web Services shows you how to do.       <br />[Emphasis mine]</p>
</blockquote>
<p>Why do we have to build web &quot;sites&quot; for humans and <em>different</em> web services for machines? I can create an ASP.NET site, a SOAP-based ASMX web service, or a SOAP or <a href="http://www.aaronlerch.com/blog/2007/08/21/creating-restful-web-services-with-wcf-35/">REST (with .NET 3.5)</a> WCF service and while they can share business logic, there&#8217;s still a lot of &quot;endpoint code&quot; (for lack of a better term) that has to be implemented, and if I want a human friendly front end + a web API, I have to build a site that essentially wraps <em>another</em> service, since the site itself really is a service.</p>
<p>With the ASP.NET MVC Framework, though, I see the opportunity to unify services and &quot;sites&quot; (human-readable services). Imagine visiting http://www.example.com/books/ and being able to receive back HTML, POX, or JSON, depending on what you asked for&#8211;with no additional code required outside of following a convention or two. Web browsers ask for HTML, returning a human consumable page that gets rendered. AJAX or custom clients can request JSON or XML, whatever they know how to interpret best.</p>
<p>The separation of concerns and extensibility that the ASP.NET MVC framework exposes lets us accomplish this with surprisingly little code. At least for read-only services (which is as far as I took it for now.) If you&#8217;re not familiar with how the ASP.NET MVC framework works, check out <a href="http://weblogs.asp.net/leftslipper/archive/2007/12/10/asp-net-mvc-design-philosophy.aspx">Eilon&#8217;s excellent ASP.NET MVC design philosophy post</a> (he also includes many good reference links).</p>
<h3>Approach</h3>
<p>Outside of the ASP.NET MVC framework itself, from an HTTP perspective I simply want to alter my response format depending on what the incoming request asked for. I decided to keep it simple and only support the &quot;<a href="http://www.rfc-editor.org/rfc/rfc2854.txt">text/html</a>&quot;, &quot;<a href="http://www.rfc-editor.org/rfc/rfc3023.txt">application/xml</a>&quot;, and &quot;<a href="http://www.ietf.org/rfc/rfc4627.txt">application/json</a>&quot; media types.</p>
<p>I started off trying to use the &quot;<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">Accept</a>&quot; HTTP header as an indicator for what response format the client preferred. After all, that&#8217;s what the Accept header is for: &quot;The Accept request-header field can be used to specify certain media types which are acceptable for the response.&quot; But I quickly ran into a snafu when I found that Firefox prefers XML over HTML.</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="167" alt="image" src="http://www.aaronlerch.com/files/blog/WebServiceswithASP.NETMVC_31B2/image.png" width="311" border="0" /> </p>
<p>That means that every request Firefox makes would result in the uber-friendly XML view.</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="179" alt="image" src="http://www.aaronlerch.com/files/blog/WebServiceswithASP.NETMVC_31B2/image_3.png" width="438" border="0" /> </p>
<p>And because of that snafu, I read up some more on the Accept header &#8211; namely what they had to say about it in an appendix of <u>RESTful Web Services</u>:</p>
<blockquote><p>Hiding this information inside the HTTP headers is a good idea for web browsers, but it shouldn&#8217;t be the only solution for web service clients. I recommend exposing different representations using different URIs. &#8230; If you want to support Accept on top of this, that&#8217;s great (Rails does this too).</p>
</blockquote>
<p>There was also some pragmatic advice in the chapter on Representations.</p>
<blockquote><p>It&#8217;s RESTful to keep this information [file format types] in the HTTP headers, and it&#8217;s RESTful to put it in the URI. I recommend keeping as much of this information as possible in the URI, and as little as possible in request metadata. I think URIs are more useful than metadata. URIs get passed around from person to person, and from program to program. The request metadata almost always gets lost in translation.</p>
</blockquote>
<p>I tend to agree with that. To make it easy and somewhat intuitive, I chose to base the response format on the existence of a querystring parameter named &quot;format&quot;. It can specify &quot;xml&quot; or &quot;json&quot;, for example http://www.example.com/books/?format=json. But really, you can use any method you want to allow format specification.</p>
<h3>Implementation</h3>
<p>Formatting the response is the responsibility of the View in the MVC architecture. Since processing requests for HTML content didn&#8217;t need to change from the default ASP.NET MVC behavior, all I need to do is override the default WebFormViewFactory functionality and return my own &quot;SerializedView&quot; if the URI indicated xml or json formatting. SerializedView is an abstract base class that encapsulates common functionality and allows sub-classes to perform the serialization, or handle custom error reporting.</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="300" alt="image" src="http://aaronlerch.com.s3.amazonaws.com/images/aspnetmvc_service_classdiagram.png" width="380" border="0" /> </p>
<p>When a Controller passes control to a View, it calls the &quot;RenderView&quot; method on the Controller base class, passing in the view name and some optional data &#8211; including something called &quot;ViewData&quot; &#8211; an object that represents the content the view should render.</p>
<p><strong>Here&#8217;s the best part:</strong> creating an ASP.NET MVC site+service using my approach means passing a serializable object as ViewData. <em>It&#8217;s as simple as that</em>, nothing else needs to change (ok, you need one additional line of code in your Application_Start handler &#8211; more on that later). In your ASPX view, you can access the object via ViewData and use all the HTML helpers, UserControls, etc. that you want to build out your HTML, javascript, and who-knows-what.</p>
<p>Unfortunately, the current CTP of the ASP.NET MVC framework does not expose a way to &quot;inject&quot; a different IViewFactory (my subclassed version) into the default Controller created by the ControllerBuilder class. So, that means implementing the IControllerFactory interface and duplicating (ouch!) the code that ControllerBuilder executes, with one somewhat nasty addition.</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="200" alt="image" src="http://www.aaronlerch.com/files/blog/WebServiceswithASP.NETMVC_31B2/image_5.png" width="680" border="0" /> </p>
<p>Yuck! The ViewFactory property is specific to the Controller class, not the IController interface, hence the specific processing &#8212; and that also means my approach won&#8217;t work for other IController implementations. Not without some extra work, anyway.</p>
<p>This is where the only change you need to make comes in. My IControllerFact<br />
ory implementation needs to be registered as the default controller factory, which is done in the Application_Start handler &#8211; the same place your routes are configured.</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="100" alt="image" src="http://www.aaronlerch.com/files/blog/WebServiceswithASP.NETMVC_31B2/image_6.png" width="910" border="0" /></p>
<h3>Serializable Types</h3>
<p>For various reasons, you should use the WCF [DataContract] and [DataMember] attributes to tag your objects as serializable. For one, you gain all the serialization benefits these attributes offer, plus you can use the same contract types across multiple endpoints if you need to. And for another, serializing to JSON via the <a title="DataContractJsonSerializer Class" href="http://msdn2.microsoft.com/bb908432.aspx">System.Runtime.Serialization.Json.DataContractJsonSerializer</a> requires the DataContract attribute. If you use the older [Serializable] attribute, you get some interesting results.</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="265" alt="image" src="http://aaronlerch.com.s3.amazonaws.com/images/aspnetmvc_service_serializedjson.png" width="390" border="0" /> </p>
<p>The deprecated <a title="JavaScriptSerializer Class" href="http://msdn2.microsoft.com/bb337495.aspx">System.Web.Script.Serialization.JavaScriptSerializer</a> works correctly for objects tagged with [Serializable] but it&#8217;s, well, deprecated.</p>
<h3>Example</h3>
<p>Using the default ASP.NET MVC Application templates, I registered the default ControllerFactory in my Application_Start handler, defined a Books controller with a default action, and a &quot;List&quot; view that prints out some Author and Title information. I also created the following definition of a book.</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="265" alt="image" src="http://www.aaronlerch.com/files/blog/WebServiceswithASP.NETMVC_31B2/image_8.png" width="365" border="0" /> </p>
<p>My controller implementation is no different than it normally would be. I get a list of books and render the &quot;List&quot; view, explicitly specifying the book list as the ViewData. You might notice that I pass the ControllerContext into the GetBooks method. I am experimenting with returning URIs to related resources as part of the data. I&#8217;m still playing around, but for now you get my latest attempt. <img src='http://www.aaronlerch.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="210" alt="image" src="http://www.aaronlerch.com/files/blog/WebServiceswithASP.NETMVC_31B2/image_9.png" width="510" border="0" /> </p>
<p>Requesting the appropriate URI in Firefox yields the expected result from my List view:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="355" alt="image" src="http://www.aaronlerch.com/files/blog/WebServiceswithASP.NETMVC_31B2/image_10.png" width="385" border="0" /></p>
<p>And altering the URI returns the appropriate response types, xml or json.</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="355" alt="image" src="http://aaronlerch.com.s3.amazonaws.com/images/aspnetmvc_service_xmlformat.png" width="385" border="0" /></p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="80" alt="image" src="http://www.aaronlerch.com/files/blog/WebServiceswithASP.NETMVC_31B2/image_12.png" width="620" border="0" /> </p>
<h3>Summary</h3>
<p>This ended up being a longer post than I intended, but I hope it was worth it. I&#8217;ve put the full source for the &quot;MvcServiceLibrary&quot; and an example up on my <a href="http://www.aaronlerch.com/blog/tools/">Tools page</a> &#8211; but <a href="http://www.aaronlerch.com/files/blog/MvcServiceLibrary.zip">here&#8217;s the direct download link</a>. I&#8217;ll also be checking if this is worth putting into the <a href="http://mvccontrib.org/">MvcContrib</a> open source project.</p>
<p>I think that the ASP.NET MVC framework is a huge step forward in creating RESTful web sites, and hopefully now also RESTful web services! Let me know what you think, I love getting feedback.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aaronlerch.com/blog/2008/01/01/unifying-web-sites-and-web-services-with-the-aspnet-mvc-framework/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>This just in:  I&#8217;m a moron.</title>
		<link>http://www.aaronlerch.com/blog/2005/12/15/this-just-in-im-a-moron/</link>
		<comments>http://www.aaronlerch.com/blog/2005/12/15/this-just-in-im-a-moron/#comments</comments>
		<pubDate>Thu, 15 Dec 2005 18:46:00 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[microsoft]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://www.aaronlerch.com/blog/2005/12/15/this-just-in-im-a-moron/</guid>
		<description><![CDATA[A while back, I posted about VS.NET not accepting non-standard ports for web services when adding them via &#8220;Add Web Reference&#8230;&#8221;.  I would like to update that post and say that boy, am I a moron.  Of COURSE it can accept non-standard ports (and I wondered how they could leave that simple &#8220;feature&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>A while back, I <a href="http://aaronlerch.blogspot.com/2005/02/referencing-web-service-using-non.html">posted</a> about VS.NET not accepting non-standard ports for web services when adding them via &#8220;Add Web Reference&#8230;&#8221;.  I would like to update that post and say that boy, am I a moron.  Of COURSE it can accept non-standard ports (and I wondered how they could leave that simple &#8220;feature&#8221; out of VS.NET!)</p>
<p>I attended the VS 2005 launch event  in my hometown today (Indianapolis), and at the &#8220;Meet the Experts&#8221; session afterwards, I presented a similar problem to the one I mentioned previously to the VS.NET 2005 expert.  Well, long story short, <a href="http://blogs.msdn.com/wsteele/">Bill Steele</a> found the solution to my problem (thank you!).  It was that the disco generated by the web service on the server (a 3rd-party web service) was incorrect, it was redirecting the WS consumer to an invalid URL (hence VS.NET wasn&#8217;t able to auto-generate the reference to it).  Well, about 10 minutes later, on my way home, it hit me like a smack in the face that the issue I previously had was with the same WS provider, and that I never did test my &#8220;issue&#8221; in my own controlled environment.  Geez.  I feel like a moron!  I would bet extremely large sums of money that it was the same issue then that I am seeing now.  (the old URL is now defunct, so I can&#8217;t test it against their server, and I don&#8217;t feel like taking the time to prove it since I&#8217;m so sure of what the problem was)  I will keep my old blog post around just to remind me to always hunt down ALL avenues&#8211;I had left one unexplored last time (and this time) and it happened to be the one place the error existed.</p>
<p>So thanks to Bill! You really are the expert!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aaronlerch.com/blog/2005/12/15/this-just-in-im-a-moron/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Contract-First Web Service Part II</title>
		<link>http://www.aaronlerch.com/blog/2005/05/19/contract-first-web-service-part-ii/</link>
		<comments>http://www.aaronlerch.com/blog/2005/05/19/contract-first-web-service-part-ii/#comments</comments>
		<pubDate>Thu, 19 May 2005 14:12:00 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://www.aaronlerch.com/blog/2005/05/19/contract-first-web-service-part-ii/</guid>
		<description><![CDATA[It&#8217;s now posted.
at MSDN
]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s now posted.</p>
<p><a href="http://msdn.microsoft.com/msdnmag/issues/05/06/ServiceStation/">at MSDN</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.aaronlerch.com/blog/2005/05/19/contract-first-web-service-part-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Contract First Web Services</title>
		<link>http://www.aaronlerch.com/blog/2005/05/04/contract-first-web-services/</link>
		<comments>http://www.aaronlerch.com/blog/2005/05/04/contract-first-web-services/#comments</comments>
		<pubDate>Wed, 04 May 2005 15:46:00 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://www.aaronlerch.com/blog/2005/05/04/contract-first-web-services/</guid>
		<description><![CDATA[Aaron Skonnard, from Pluralsight, has written a great 2-part article on developing Contract-First Web Services.
I&#8217;ve had the privilege of getting my hands on both of the articles before they were released (the first was recently released, the second is still pending) and used them as a strong resource when developing a Web Service I&#8217;ve been [...]]]></description>
			<content:encoded><![CDATA[<p>Aaron Skonnard, from <a href="http://www.pluralsight.com/blogs/aaron/default.aspx">Pluralsight</a>, has written a great 2-part article on developing Contract-First Web Services.</p>
<p>I&#8217;ve had the privilege of getting my hands on both of the articles before they were released (the first was recently released, the second is still pending) and used them as a strong resource when developing a Web Service I&#8217;ve been working on for the past few months (on the side).</p>
<p>I am going to echo Aaron&#8217;s complaint that tool support for contract-first development is limited (regarding Web Services anyway) and while the WSContractFirst tool he mentions is nice as it integrates fully with Visual Studio .NET, it leaves a little to be desired.  I found that once I wanted to change my WSDL (my contract) I either had to re-create the entire thing, or make my changes manually and then circumvent the convenience offered by the tool and use the VS.NET-supplied Web Service proxy generator (wsdl.exe).<br />
Admittedly I never tried using a WSDL editor, I just did it by hand (a pain!), so perhaps my frustration is self-generated. Either way I think I would like to try my hand at creating a WSDL generating tool that integrates with VS.NET.  But I wouldn&#8217;t like to try too hard, for several reasons:<br />
1. Time<br />
2. According to Aaron, Visual Studio 2005 (Whidbey) is going to contain some enhancements in this area already. So do I really want to re-invent the yet-to-be-invented wheel?<br />
3. Did I mention time?</p>
<p>If you read this and have any suggestions, please let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aaronlerch.com/blog/2005/05/04/contract-first-web-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Referencing a web service using a non-standard port in Visual Studio .NET 2003</title>
		<link>http://www.aaronlerch.com/blog/2005/02/21/referencing-a-web-service-using-a-non-standard-port-in-visual-studio-net-2003/</link>
		<comments>http://www.aaronlerch.com/blog/2005/02/21/referencing-a-web-service-using-a-non-standard-port-in-visual-studio-net-2003/#comments</comments>
		<pubDate>Mon, 21 Feb 2005 19:12:00 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://www.aaronlerch.com/blog/2005/02/21/referencing-a-web-service-using-a-non-standard-port-in-visual-studio-net-2003/</guid>
		<description><![CDATA[Twice now I&#8217;ve come across this issue, so I&#8217;m documenting it here.
Adding a web service reference that doesn&#8217;t use the standard port (80) through Visual Studio .NET 2003&#8217;s &#8220;Add Web Reference&#8221; interface will cause you all kinds of pain. The issue is that although you can include a port number when specifying the URL for [...]]]></description>
			<content:encoded><![CDATA[<p>Twice now I&#8217;ve come across this issue, so I&#8217;m documenting it here.</p>
<p>Adding a web service reference that doesn&#8217;t use the standard port (80) through Visual Studio .NET 2003&#8217;s &#8220;Add Web Reference&#8221; interface will cause you all kinds of pain. The issue is that although you can include a port number when specifying the URL for the web service, the underlying tools that generate the proxy classes and the .disco file will strip it out without telling you.</p>
<p>So when I add a reference to &#8220;http://www.webserviceserver.com:5332/service.asmx&#8221;, the end result in the .disco and .cs files is a reference to &#8220;http://www.webserviceserver.com/service.asmx&#8221; which obviously doesn&#8217;t work.</p>
<p>So here&#8217;s the fix: (if someone knows a better one, please post it in the comments!)</p>
<ol>
<li>Add the web reference, but when it times out and fails, instruct VS.NET to continue processing the files. This will create the Reference.cs file (which will just contain a namespace), Reference.map, and the .disco file.</li>
<li>Edit the .disco file in a text editor (VS.NET will work great), and alter the following:
<ol>
<li>In the <font face="courier new">&lt;contractRef&gt;</font> element, edit the &#8220;<font face="courier new">ref</font>&#8221; and &#8220;<font face="courier new">docRef</font>&#8221; attributes to include the correct port number</li>
<li>In the <font face="courier new">&lt;soap&gt;</font> element, edit the &#8220;<font face="courier new">address</font>&#8221; element to include the correct port number</li>
</ol>
</li>
<li>Open a Visual Studio command prompt window (for my default install, I can get to this from &#8220;Start -&gt; All Programs -&gt; Microsoft Visual Studio .NET 2003 -&gt; Visual Studio .NET Tools -&gt; Visual Studio .NET 2003 Command Prompt&#8221;). This will open a command prompt with all the required paths set to access the Visual Studio .NET command-line tools.</li>
<li>Navigate to your project folder, and go into the Web References\[webservice] subfolder. Use wsdl.exe to create the proxy class for use in Visual Studio:
<ol>
<li>Type &#8220;wsdl.exe [full web service URL - with port number]&#8221; &#8212; This will generate a .cs file that has the same name as your .disco file (hopefully). Regardless, just look for the new .cs file that exists in the folder.</li>
<li>If you&#8217;re interested in the wsdl.exe tool, type &#8220;wsdl.exe&#8221; at the command line to see the options available. If you&#8217;re implementing your web service properly, you should be familiar with this tool as you can use it to create your web service &#8220;contract-first&#8221;. Check out the blogs at <a href="http://www.pluralsight.com/">pluralsight.com</a> for more info on that important topic.</li>
</ol>
</li>
<li>Open Reference.cs and the newly created class file from step 4 in an editor (like VS.NET). You should notice that the Reference.cs file contains only the namespace keyword (along with a namespace identifier) and nothing else. Copy the &#8220;using&#8221; statements from the wsdl.exe generated class file above the &#8220;namespace [namespace id]&#8221; line in Reference.cs. Then copy the entire implementation portion of the web service proxy code from the generated class file into Reference.cs, inside the namespace declaration.</li>
<li>[ALTERNATE STEP 5] Simply open the generated class file and wrap the entire thing (minus the &#8220;using&#8221; statements) in a namespace declaration. Then add the new .cs file into your project. Note that this won&#8217;t show up under &#8220;Web References&#8221;, however.</li>
<li>Finally, edit the final file (depending if you did step 5 or 6), find the constructor for the main class (the class that derives from <font face="courier new">System.Web.Services.Protocols.SoapHttpClientProtocol</font>), and change the &#8220;<font face="courier new">this.Url</font>&#8221; property assignment line of code to point to the correct URL. This should just mean adding the port number into the URL string.</li>
</ol>
<p>And there you have it. A pain in the butt? Yes. Which reminds me, attempt to refrain from right-clicking on the web reference and choosing &#8220;Update Web Reference&#8221; as this will overwrite your files (if you select &#8220;Continue&#8221; when it times out instead of choosing &#8220;Skip&#8221;). If you do need to update the web reference, you will have to repeat all these steps. Generate the proxy from the WSDL and copy the code into the Reference.cs file. Blech.</p>
<p>Another note is that using the disco tool doesn&#8217;t fare any better than the IDE (probably because the IDE uses the tool indirectly). It will also fail because it attempts to access the web service on port 80.</p>
<p>I apologize for the lack of screenshots, I am still trying to figure out the best way to host pictures on here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aaronlerch.com/blog/2005/02/21/referencing-a-web-service-using-a-non-standard-port-in-visual-studio-net-2003/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
