<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Peter McIntyre</title>
	<atom:link href="http://petermcintyre.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://petermcintyre.com</link>
	<description>Professor &#124; Seneca College &#124; Toronto Canada</description>
	<lastBuildDate>Fri, 20 Apr 2012 14:50:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='petermcintyre.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/6ce41b556e340ad97612d37d4027c21e?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Peter McIntyre</title>
		<link>http://petermcintyre.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://petermcintyre.com/osd.xml" title="Peter McIntyre" />
	<atom:link rel='hub' href='http://petermcintyre.com/?pushpress=hub'/>
		<item>
		<title>One-page web programming course</title>
		<link>http://petermcintyre.com/2012/04/12/one-page-web-programming-course/</link>
		<comments>http://petermcintyre.com/2012/04/12/one-page-web-programming-course/#comments</comments>
		<pubDate>Thu, 12 Apr 2012 21:57:31 +0000</pubDate>
		<dc:creator>petermcintyre</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Web client development]]></category>

		<guid isPermaLink="false">http://petermcintyre.com/?p=5110</guid>
		<description><![CDATA[Back story I teach web programming courses. In our school (in early 2012), we are refreshing the introductory web programming courses to cover modern yet mainstream topics. During our discussions, I was challenged to make my views clear and understandable to all, whether they were new to web programming, or whether they had past knowledge [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=5110&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h4>Back story</h4>
<p>I teach web programming courses. In our school (in early 2012), we are refreshing the introductory web programming courses to cover modern yet mainstream topics.</p>
<p>During our discussions, I was challenged to make my views clear and understandable to all, whether they were new to web programming, or whether they had past knowledge and experience. I thought about the challenge for awhile, and decided to publish this &#8220;one-page web programming course&#8221;. That was my goal &#8211; an introduction to web programming, for someone who is new to this topic, on one page. It fits on one web page (ha ha), and it fits on one printed page (with a small font size ☺ ).</p>
<p>Comments and feedback invited. The first time you read it, don&#8217;t stop to click the links. Just read it through. Then, you can go back and click the links to learn more, if you like.</p>
<p>.</p>
<h4>One-page web programming course</h4>
<p>You have decided to learn web programming. Well, you need to learn something about four things:</p>
<ol>
<li>Web page definition, structure, and content</li>
<li>Web page appearance</li>
<li>Web page programming</li>
<li>Web page publishing</li>
</ol>
<p><strong>What is a web page?</strong> It is a document.</p>
<p><strong>How do you view a web page?</strong> With a program called a <a href="http://en.wikipedia.org/wiki/Web_browser" target="_blank">web browser</a>.</p>
<p><strong>What does a web page contain?</strong> Content, and <a href="http://en.wikipedia.org/wiki/Markup_language" target="_blank">markup</a> text. <a href="http://en.wikipedia.org/wiki/Html" target="_blank">HTML</a> is the markup language that&#8217;s used on web pages. The HTML markup will often also include CSS and JavaScript, which are explained later.</p>
<p><strong>How is a web page organized? Does it have a structure?</strong> Yes. A web page (document) must conform to the <a href="http://en.wikipedia.org/wiki/Document_object_model" target="_blank">document object model</a> (DOM) <a href="http://www.w3.org/DOM/" target="_blank">standard</a>. You should know three things about the DOM:</p>
<ol>
<li>It describes a document&#8217;s parts or components (e.g. head, title, body, etc.).</li>
<li>A document is exposed as an object, which means that its structure and content can be manipulated (i.e. viewed, queried, changed, etc.).</li>
<li>The DOM broadcasts events (e.g click, mouse over, etc.), which enables a listener to perform an action.</li>
</ol>
<p><strong>What is HTML? </strong>As noted above, it is a <a href="http://en.wikipedia.org/wiki/Declarative_programming" target="_blank">declarative</a> markup language that describes the structure and contents of a document. There are about 100 <a href="http://en.wikipedia.org/wiki/HTML_element" target="_blank">elements</a> that can be used. All documents include a head element, and a body element. Within each of these, we add other elements (e.g. a title in the head, and structural divisions and content paragraphs in the body), and content.</p>
<p>The syntax used to describe document elements conforms to this format:</p>
<p>&lt;element attribute1=&#8221;value1&#8243;&gt;Optional content&lt;/element&gt;</p>
<p>Notice the start &#8220;tag&#8221;, which begins with &#8220;&lt;ele…&#8221;. Also notice the end &#8220;tag&#8221;, which places a slash character before the element name, e.g. &#8220;&lt;/ele…&#8221;.</p>
<p><strong>How do we identify and locate document elements?</strong> There&#8217;s an easy way to identify and address document elements by their element name. There&#8217;s also an easy way to identify and address a selection of document elements, by using a programmer-specified &#8220;class name&#8221;, and marking the appropriate document elements to use the class name. Finally, there&#8217;s also an easy way to identify and address a specific document element, by marking the element with a programmer-specified unique identifier.</p>
<p><strong>How can we change the document&#8217;s appearance?</strong> We use <a href="http://en.wikipedia.org/wiki/Cascading_Style_Sheets" target="_blank">CSS</a> rules. The way in which a programmer and designer can affect the document&#8217;s appearance is almost unlimited. To use CSS effectively, you must know about the document&#8217;s structure, the DOM.</p>
<p><strong>What is CSS?</strong> It is a declarative language that is used to describe the appearance of an HTML document. The language statements are called rules. There are rules that affect layout and positioning, fonts, and visuals such as colours and images.</p>
<p>CSS rules can be placed in a separate source code file, and then linked to a document. Alternatively, CSS rules can be placed in the head of a document, or in a document element&#8217;s start tag.</p>
<p>The syntax used to describe CSS rules conforms to this format (when located in a separate source code file, or in the head of a document):</p>
<p>ruleName { rule1: value1; rule2: value2 }</p>
<p>The &#8220;ruleName&#8221; is known as a selector. It can be a document element name, a programmer-specified class name, or a programmer-specified unique identifier name.</p>
<p><strong>How can we make a document interactive and functional?</strong> We use <a href="http://en.wikipedia.org/wiki/Javascript" target="_blank">JavaScript</a>.</p>
<p><strong>What is JavaScript?</strong> It is a programming language that can access and manipulate a document. JavaScript is the programming language for web pages.</p>
<p>A document can display static content. However, a document can also be interactive and functional by using JavaScript. For example, the document&#8217;s structure, content, and appearance can be modified, based upon user interaction, or some other event or stimulus. JavaScript can also access the web, and fetch data from a web server. The new data can then be used to modify the document&#8217;s content and experience, if desired.</p>
<p>JavaScript source code can be placed in a separate source code file, and then linked to a document. Alternatively, it can be placed in the document (head or body), or in the document&#8217;s elements or content.</p>
<p><strong>How can we make our document available to the public?</strong> We publish it to a <a href="http://en.wikipedia.org/wiki/Web_application" target="_blank">web app</a>.</p>
<p><strong>What is a web app?</strong> It is a program, which runs on a <a href="http://en.wikipedia.org/wiki/Web_server" target="_blank">web server</a>, and responds to requests from browsers. The requests and responses conform to the <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol" target="_blank">HTTP</a> protocol.</p>
<p>A web app can serve <a href="http://en.wikipedia.org/wiki/Static_web_page" target="_blank">static resources</a> (including web pages and images), which means that the web app simply retrieves the resource from the web server&#8217;s file system, and returns it to the browser.</p>
<p>However, a web app can also dispatch a request to an executable resource (i.e. a program), which will process the request, <a href="http://en.wikipedia.org/wiki/Dynamic_web_page" target="_blank">dynamically generate</a> an appropriate response, and return it to the browser.</p>
<p>.</p>
<hr noshade="noshade" size="11" />
<p>.</p>
<p>.</p>
<p>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/petermcintyre.wordpress.com/5110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/petermcintyre.wordpress.com/5110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/petermcintyre.wordpress.com/5110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/petermcintyre.wordpress.com/5110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/petermcintyre.wordpress.com/5110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/petermcintyre.wordpress.com/5110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/petermcintyre.wordpress.com/5110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/petermcintyre.wordpress.com/5110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/petermcintyre.wordpress.com/5110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/petermcintyre.wordpress.com/5110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/petermcintyre.wordpress.com/5110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/petermcintyre.wordpress.com/5110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/petermcintyre.wordpress.com/5110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/petermcintyre.wordpress.com/5110/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=5110&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://petermcintyre.com/2012/04/12/one-page-web-programming-course/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d94ddb24521352b6287292b05c01323?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">petermcintyre</media:title>
		</media:content>
	</item>
		<item>
		<title>Learning Objective-C &#8211; the top ten list</title>
		<link>http://petermcintyre.com/2011/12/21/learning-objective-c-the-top-ten-list/</link>
		<comments>http://petermcintyre.com/2011/12/21/learning-objective-c-the-top-ten-list/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 14:24:11 +0000</pubDate>
		<dc:creator>petermcintyre</dc:creator>
				<category><![CDATA[2011 Fall DPS913]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iOS Cocoa Touch]]></category>
		<category><![CDATA[Mac OS X]]></category>

		<guid isPermaLink="false">http://petermcintyre.com/?p=4417</guid>
		<description><![CDATA[When we begin to learn a new computer programming language, we often try to get acquainted with the language by applying our current knowledge to its characteristics. This &#8220;top ten&#8221; list captures this process. . As a third- or fourth-year student, you have some experience with a number of programming languages. Let&#8217;s begin to learn [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=4417&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When we begin to learn a new computer programming language, we often try to get acquainted with the language by applying our current knowledge to its characteristics. This &#8220;top ten&#8221; list captures this process.</p>
<p>.</p>
<p>As a third- or fourth-year student, you have some experience with a number of programming languages. Let&#8217;s begin to learn about Objective-C by asking questions in the form of a &#8220;top ten&#8221; list. (Note that you can ask these questions about <strong>ANY</strong> language.)</p>
<blockquote><p>Note: Objective-C is the name of the programming language. It adds a small number of object-oriented extensions to the standard C language.</p>
<p>Cocoa is the name of the the class library and runtime. The classes are organized into &#8220;frameworks&#8221;. Your app will link to one or more frameworks.</p>
<p>So, in summary, to create apps for iOS and Mac OS X, you write code using the Objective-C language, and use Cocoa classes.</p></blockquote>
<p>.</p>
<h4>The &#8220;top ten&#8221; list of questions</h4>
<p>Here is the &#8220;top ten&#8221; list of questions to ask when learning Objective-C:</p>
<p>1. How do I create/edit/save the source code? What editor do I use? Where do I store the source code? What is the source code file naming convention?</p>
<p>2. How do I build/compile and then execute/run my program? Is there a compiler? Is there a host execution (aka &#8220;runtime&#8221;) environment?</p>
<p>3. What is the program&#8217;s entry point? Syntactically, what coding convention must I follow?</p>
<p>4. What data types can I use? Are they categorized (e.g. value/stack, reference/heap), and if so, what do I need to know about their characteristics (e.g. size, initial value, precision, convertibility, etc.)?</p>
<p>5. How do I declare new variables/fields of a data type? How do I instantiate them? How do I refer to and use these variables/fields? (Note that a type could be a class declaration for an object-oriented language and platform.)</p>
<p>6. What operators are available to me in this language? (How do they compare to other languages that I&#8217;m familiar with?)</p>
<p>7. What is the syntax of a statement, and of an expression? What delimiters are used? How is scope and hierarchy expressed?</p>
<p>8. What syntax enables me to process a decision (e.g. if-else, or switch-case)?</p>
<p>9. What syntax enables me to process repeatedly (e.g. for, while)?</p>
<p>10. How are functions (methods) declared? What rules are there for argument/parameter declaration? How are functions used/called? Are the arguments passed by value, or by reference?</p>
<p>Bonus:</p>
<p>11. Where do I get learning/tutorial information? Where do I get reference information? Where do I look for good-quality online information?</p>
<p>.</p>
<h4>The answers</h4>
<p>Here are the answers. We cover them in class, and we go through some examples.</p>
<p><strong>1. How do I create/edit/save the source code? What editor do I use? Where do I store the source code? What is the source code file naming convention? </strong></p>
<blockquote><p>You write source code with Xcode, Apple&#8217;s integrated development environment (IDE).</p>
<p>An app is typically organized as a &#8220;project&#8221;, which appears as a folder in the file system. In that folder, your source code is stored in text files, and you will also find &#8220;resources&#8221; for your app, such as images, configuration settings, and so on.</p>
<p>Objective-C is a header-based language. You define a class&#8217;s interface in a text file that has a .h extension (e.g. Person.h). The class&#8217;s implementation code is located in a text file that has a .m extension (e.g. Person.m).</p>
<p>Most often, you create classes for your app. A class can be used to perform tasks (e.g. a &#8220;controller&#8221;), or it can be used to represent real-world objects (e.g. a &#8220;model&#8221;).</p></blockquote>
<p>.</p>
<p><strong>2. How do I build/compile and then execute/run my program? Is there a compiler? Is there a host execution (aka &#8220;runtime&#8221;) environment? Does it control the application lifecycle?</strong></p>
<blockquote><p>In Xcode, you can use a &#8220;build&#8221; command (or one of its variants) to build/compile your program. Its command key shortcut is Command+B.</p>
<p>To run your program, you first select an execution target (e.g. a simulator, or a device), and then you use a &#8220;run&#8221; command. Its shortcut is Command+R.</p>
<p>Cocoa is the execution runtime environment. Your app runs under the control of Cocoa. Cocoa sends your app messages when something happens in the environment (e.g. a user touches/taps the screen, or data arrives from the network.</p>
<p>In summary, Cocoa is in control.</p></blockquote>
<p>.</p>
<p><strong>3. What is the program&#8217;s entry point? Syntactically, what coding convention must I follow? </strong></p>
<blockquote><p>As a C-based language, the main() function is your app&#8217;s entry point. When a user starts/launches your app, the main() function runs.</p>
<p>For a typical iOS or Mac OS X app, main() calls a function that loads the app into the Cocoa runtime environment. At that point in time, as noted above, the Cocoa runtime is in control.</p>
<p>The Xcode project templates all include the main.m source code module, which has the main() function. Typically, you do not ever have to edit main.m.</p></blockquote>
<p>.</p>
<p><strong>4. What data types can I use? Are they categorized (e.g. value/stack, reference/heap), and if so, what do I need to know about their characteristics (e.g. size, initial value, precision, convertibility, etc.)? </strong></p>
<blockquote><p>Your apps can use C language types, and Cocoa types, in any combination.</p>
<p>Most of the time, you will prefer to use Cocoa types. For example, NSString offers rich functionality for strings. NSArray is a collection class, for elements/members of any Cocoa type.</p>
<p>C language types, including structs, are value (scalar) types.</p>
<p>Cocoa type instances are reference types. The instance name is a pointer to the memory that holds the instance&#8217;s data.</p>
<p>The initial value of a type instance varies by type. Sometimes, you get &#8220;nil&#8221;, or nothing. Other times, you get a working object, with empty or nil fields (properties).</p>
<p>As you would expect, most convertible types have methods which enable type conversion. For example, NSString has an intValue method, which attempts to return an integer of the string instance.</p>
<p>You can create your own types. Objective-C is a header-based language:</p>
<ul>
<li>The public interface (methods and properties) is defined in a source code file which has a .h extension. The definitions are placed between an @interface statement and an @end statement.</li>
<li>The implementation code is located in a source code file which has a .m extension. The code is placed between an @implementation statement and an @end statement.</li>
</ul>
</blockquote>
<p>.</p>
<p><strong>5. How do I declare new variables/fields of a data type? How do I instantiate them? How do I refer to and use these variables/fields? (Note that a type could be a class declaration for an object-oriented language and platform.)</strong></p>
<blockquote><p>For C language types, simply use the C language semantics. For example:</p>
<p>int i = 5;</p>
<p>For Objective-C (Cocoa) types, you must create an instance of the desired type. There are two ways to initialize a new object:</p>
<ol>
<li>Use the type&#8217;s designated initializer</li>
<li>Use a &#8220;class method&#8221;</li>
</ol>
<p>.</p>
<p><span style="text-decoration:underline;">Using an initializer:</span></p>
<p>Most Objective-C types include one or more initializer methods. (In C# and Java, you know these methods as &#8220;constructors&#8221;.)</p>
<p>Almost every type supports the base initializer, called &#8220;init&#8221;.</p>
<p>A type designer can create more initializers, which can accept arguments. If there&#8217;s more than one initializer, the type designer will make one of them the &#8220;designated initializer&#8221;, which is the one that performs the initialization. (If the developer uses another initializer, that initializer will ultimately call the designated initializer.) Initializers should always begin with &#8220;init&#8221;.</p>
<p>The following shows two examples that use an initializer:</p>
<p>NSMutableString *s = [[NSMutableString alloc] init];</p>
<p>Person *p = [[Person alloc] initWithLastname:@&#8221;McIntyre&#8221; andFirstName:@&#8221;Peter&#8221;];</p>
<p>.</p>
<p><span style="text-decoration:underline;">Using a class method:</span></p>
<p>Many Objective-C types offer one or more class methods that initialize a new object. (In C# and Java, these are known as &#8220;static methods&#8221;.)</p>
<p>They are also known as &#8220;convenience&#8221; (or &#8220;factory&#8221;) methods. They make it really easy to create an object. Initializer class methods may or may not accept arguments, it depends upon their design.</p>
<p>The following shows two examples that use class methods. Assume that &#8220;lname&#8221; and &#8220;fname&#8221; are existing NSString objects:</p>
<p>NSString *s = [NSString stringWithFormat:@"My name is %@ %@", fname, lname];</p>
<p>Person *p = [Person personWithFirstName:fname andLastName:lname];</p>
<p>.</p>
<p>As you would expect (in other languages), you refer to the new objects by using their instance name. You would simply use &#8220;s&#8221; to refer to the NSString object above. Or, &#8220;p&#8221; to refer to the Person object above.</p>
<p>As you would do in C, if you wanted the memory address of &#8220;s&#8221; or &#8220;p&#8221;, use the &#8220;&amp;&#8221; symbol. So, the address of s would be &#8220;&amp;s&#8221;.</p>
<p>As you would do in C, if you wanted the pointer to &#8220;s&#8221;, use the &#8220;*&#8221; symbol. However, as it turns out, this is infrequently used.</p></blockquote>
<p>.</p>
<p><strong>6. What operators are available to me in this language? (How do they compare to other languages that I&#8217;m familiar with?) </strong></p>
<blockquote><p>The standard C operators are available.</p>
<p>When working with objects, you will typically call an object&#8217;s methods, to perform operations, or access state through getters and setters. Some objects have properties, which you can access using a dot operator.</p></blockquote>
<p>.</p>
<p><strong>7. What is the syntax of a statement, and of an expression? What delimiters are used? How is scope and hierarchy expressed? </strong></p>
<blockquote><p>Standard C language rules apply for statements, expression, delimiters, scope, and hierarchy.</p>
<p>However, when calling a method on an Objective-C object, a square-bracket syntax is used. The syntax is obviously quite different from C and other C-family object-oriented languages.</p>
<p>In the example that follows, we &#8220;convert&#8221; a string, which is holding an integer, into a C scalar, by calling the string&#8217;s &#8220;intValue&#8221; method. (The string comes from a &#8220;Label&#8221; control &#8211; which is an object &#8211; in the user interface).</p>
<p>int n = [lblAge.Text intValue];</p></blockquote>
<p>.</p>
<p><strong>8. What syntax enables me to process a decision (e.g. if-else, or switch-case)? </strong></p>
<blockquote><p>Objective-C is a C-family language, so its statement syntax is similar. if-else (including the ? : syntax) and switch-case are available.</p></blockquote>
<p>.</p>
<p><strong>9. What syntax enables me to process repeatedly (e.g. for, while)? </strong></p>
<blockquote><p>Objective-C is a C-family language, so its statement syntax is similar. for and while are available. There is also a foreach enumerator form of the for statement.</p></blockquote>
<p>.</p>
<p><strong>10. How are functions (methods) declared? What rules are there for argument/parameter declaration? How are functions used/called? Are the arguments passed by value, or by reference?</strong></p>
<blockquote><p>Objective-C is a C-family language, so you declare and call functions in a similar way.</p>
<p>In an Objective-C class, you define (then implement) its public interface with methods and properties. There are two kinds of methods: 1) Class methods, and 2) Instance methods:</p>
<ol>
<li>A class method can be called directly, without creating an instance of the class.</li>
<li>An instance method can be called on an instance of the class.</li>
</ol>
<p>.</p>
<p>The definition of a method is similar to C, but there are two important differences:</p>
<ol>
<li>The method definition (and implementation) is preceded by a + (plus sign) for a class method, and by a &#8211; (minus sign) for an instance method.</li>
<li>The method parameters (arguments) are named.</li>
</ol>
<p>.</p>
<p>Here are a few examples, using the &#8220;Person&#8221; examples from above (in question 5).</p>
<p>// Instance method definition/declaration<br />
- (NSString *)newPhoneNumber:(NSString *)phoneNumber forPhoneNumberType:(NSString *)phoneNumberType;</p>
<p>// Class method definition/declaration<br />
+ (Person *)personWithFirstName:(NSString *)firstName andLastName:(NSString *)lastName;</p>
<p>.</p>
<p>The name of the instance method (above) is:</p>
<p>newPhoneNumber:forPhoneNumberType:</p>
<p>Notice that the name includes each argument, and the colons.</p>
<p>.</p>
<p>To call a method, use the syntax that you saw in question 5 above:</p>
<p>// Calling an instance method<br />
Person *p = [[Person alloc] initWithLastname:@&#8221;McIntyre&#8221; andFirstName:@&#8221;Peter&#8221;];</p>
<p>// Calling a class method<br />
Person *p = [Person personWithFirstName:fname andLastName:lname];</p>
<p>.</p>
<p>In Objective-C, the phrase &#8220;calling a method&#8221; is not used as a first choice. Instead, we use the phrase &#8220;sending a message (to an object)&#8221;, or more simply, &#8220;messaging&#8221;.</p>
<p>.</p>
<p>Parameters (arguments) are passed by value (like in C). However, please note that you often pass a pointer, so you are effectively passing a reference.</p></blockquote>
<p>.</p>
<p><strong>11. Where do I get learning/tutorial information? Where do I get reference information? Where do I look for good-quality online information? </strong></p>
<blockquote><p>Your professor recommends the Apple developer documentation.</p>
<p>To get started, and learn effectively through discussion and demonstration, you must attend all lectures. Then, you can augment your learning with three kinds of Apple documentation:</p>
<p><strong>1) Competencies Documents</strong></p>
<p>Apple publishes two sets of well-written technology introductions. One set covers both iOS and Mac OS X, and is available here:</p>
<p><a href="http://developer.apple.com/library/mac/#documentation/General/Conceptual/DevPedia-CocoaCore/AccessorMethod.html" target="_blank">Cocoa Core Competencies</a></p>
<p>The other set covers topics that are specific to iOS:</p>
<p><a href="http://developer.apple.com/library/ios/#documentation/General/Conceptual/Devpedia-CocoaApp/ApplicationObject.html" target="_blank">Cocoa Application Competencies for iOS</a></p>
<p>Each document is a brief introduction to a topic, and includes links to a &#8220;definitive discussion&#8221; document, which is usually a developer guide.</p>
<p>.</p>
<p><strong>2) Developer Guides </strong></p>
<p>Apple publishes a large number of developer guides. These documents range in size from tens of pages, to hundreds of pages. They include discussion, best-practice advice, code samples, and other information that&#8217;s valuable to the developer.</p>
<p>Developer guides are organized on a per-topic basis. You can see the complete list of guides by viewing the <a href="http://developer.apple.com/library/ios/navigation/" target="_blank">iOS Developer Library</a> (after you login to the iOS Dev Center). On the left side, under &#8220;Resource Types&#8221;, click &#8220;Guides&#8221;.</p>
<p>A student should look for a developer guide after looking for and viewing a &#8220;competencies&#8221; document.</p>
<p>.</p>
<p><strong>3) Reference Documents</strong></p>
<p>Objective-C and Cocoa classes are well-documented in &#8220;reference&#8221; documentation. For a class reference (e.g. <a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextField_Class/Reference/UITextField.html" target="_blank">UITextField Class Reference</a>), you will get overview information, as well as detailed syntax and usage for methods and properties.</p>
<p>.</p>
<p>The online iOS Dev Center is also your source for videos, code samples, Xcode information, and so on.</p>
<p>.</p>
<p>For non-Apple resources, the StackOverflow web site is acceptable. In addition, a few other web properties are useful from time to time, and they will be referenced in the notes during the semester.</p>
<p>Note: Your professor&#8217;s opinion is that you should avoid getting answers and code samples from search engine results. Typically, the information and code is low quality, and will distract you from learning the material. (Your professor is trying to be as kind as he can be with his phrasing here.)</p></blockquote>
<p>.</p>
<hr noshade="noshade" size="11" />
<p>.</p>
<p>.</p>
<p>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/petermcintyre.wordpress.com/4417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/petermcintyre.wordpress.com/4417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/petermcintyre.wordpress.com/4417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/petermcintyre.wordpress.com/4417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/petermcintyre.wordpress.com/4417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/petermcintyre.wordpress.com/4417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/petermcintyre.wordpress.com/4417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/petermcintyre.wordpress.com/4417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/petermcintyre.wordpress.com/4417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/petermcintyre.wordpress.com/4417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/petermcintyre.wordpress.com/4417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/petermcintyre.wordpress.com/4417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/petermcintyre.wordpress.com/4417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/petermcintyre.wordpress.com/4417/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=4417&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://petermcintyre.com/2011/12/21/learning-objective-c-the-top-ten-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d94ddb24521352b6287292b05c01323?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">petermcintyre</media:title>
		</media:content>
	</item>
		<item>
		<title>Introduction to Cocoa programming on Mac OS X for iOS programmers</title>
		<link>http://petermcintyre.com/2011/12/06/intro-to-mac-os-cocoa-pgmg-for-ios-devs/</link>
		<comments>http://petermcintyre.com/2011/12/06/intro-to-mac-os-cocoa-pgmg-for-ios-devs/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 22:55:43 +0000</pubDate>
		<dc:creator>petermcintyre</dc:creator>
				<category><![CDATA[2011 Fall DPS913]]></category>
		<category><![CDATA[Mac OS X]]></category>

		<guid isPermaLink="false">http://petermcintyre.com/?p=4404</guid>
		<description><![CDATA[This post will help the iOS programmer get started with Cocoa programming on Mac OS X. This document was most recently updated in December 2011. . We have the following goals for this part of the course: Orient the iOS developer to Mac OS development, specifically Cocoa Leverage your existing knowledge Think about making a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=4404&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post will help the iOS programmer get started with Cocoa programming on Mac OS X.</p>
<p>This document was most recently updated in December 2011.</p>
<p>.</p>
<p>We have the following goals for this part of the course:</p>
<ul>
<li>Orient the iOS developer to Mac OS development, specifically Cocoa</li>
<li>Leverage your existing knowledge</li>
<li>Think about making a Mac OS companion for your iOS app</li>
<li>Highlight a few interesting features of Cocoa for Mac OS apps</li>
</ul>
<p>.</p>
<h4>Getting started with Mac OS programming</h4>
<p>The iOS developer can take advantage of what they know to get started with Mac OS programming. The language (Objective-C) is the same, and many of the Cocoa frameworks are the same.</p>
<p>The way in which data is persisted is the same. You can use a plist file (for arrays and dictionaries), archiving (for any type of object), and Core Data. The application also has access to data stored at network locations.</p>
<p>On iOS, the developer has <strong>UIKit</strong>, a framework with user interface classes that were designed for the iOS. On Mac OS, the developer uses <strong>AppKit</strong>, a richer set of user interface classes. The iOS offers the developer and user a single window, and a screen-at-a-time way of working with the application. The Mac OS enables the developer to use a larger screen, which allows the use of multiple windows.</p>
<p>Mac OS apps can be built as &#8220;document-based&#8221; applications, which means that the user is able to create, work with, and save document-oriented data. What format of data? What type? Well, it&#8217;s up to the developer. It can be as simple as a single data type (e.g. a text string in a text editor application), or a complex object graph, where (for example) a document consists of data that&#8217;s displayed in a tabular and/or graphical format, along with other data that helps make up a complete document. Document-based applications typically enable the user to &#8220;File &gt; New&#8221; (Command+N), &#8220;File &gt; Save&#8221; (Command+S), close (Command+W), and print (Command+P) documents.</p>
<p>When creating a new project, the Mac OS programming beginner will select one of the &#8220;Mac OS X&#8221; templates. For the first few projects, choose the Application &gt; Cocoa Application template. Then, you can choose, with a check box, to create a document-based application, and/or use Core Data in your application.</p>
<p>A Mac OS app that doesn&#8217;t use either documents or Core Data gets created with the following:</p>
<ul>
<li>Application delegate &#8211; similar in function and purpose to the iOS implementation</li>
<li>MainMenu nib &#8211; holds the menu choices, and a window object for the user interface</li>
</ul>
<p>A Mac OS app that is based on the document-based template gets created with the following:</p>
<ul>
<li>MyDocument controller class &#8211; similar in concept to an iOS view controller class</li>
<li>MainMenu nib &#8211; holds only the menu choices</li>
<li>MyDocument nib &#8211; holds the window, the view (user interface), and works with the MyDocument controller</li>
</ul>
<p>A Mac OS app that uses Core Data but isn&#8217;t a document-based app gets created with the following:</p>
<ul>
<li>Application delegate</li>
<li>MainMenu nib</li>
<li>Core Data model</li>
</ul>
<p>A Mac OS app that uses Core Data and the document-based template gets created with the following:</p>
<ul>
<li>MyDocument controller class</li>
<li>MainMenu nib</li>
<li>MyDocument nib</li>
<li>Core Data model</li>
</ul>
<p>.</p>
<h4>Memory management</h4>
<p>Mac OS apps offer automatic memory management. This is new for iOS (4.x and earlier) developers, who must know and use memory management techniques.</p>
<p>Therefore, in Mac OS apps, you do not have to be concerned with reference counting, retain/release, and so on.</p>
<p>.</p>
<h4>Example apps introduction</h4>
<p>We have a number of example apps today:</p>
<ul>
<li>HelloWorld</li>
<li>Bound slider</li>
<li>Professors base</li>
<li>Professors save and load</li>
</ul>
<p>.</p>
<p>One is a real simple &#8220;hello world&#8221; app, that highlights a few differences between a Mac OS app and an iOS app.</p>
<p>The third app is actually one that we configure with a base level of functionality, and then add on some features in a subsequent version. In between, we look at an example that clearly shows the Cocoa Bindings feature.</p>
<p>.</p>
<h4>HelloWorld sample app</h4>
<p><img style="display:inline;border:0 initial initial;margin:0 0 25px 25px;" title="HelloWorld" src="http://petermcintyre.files.wordpress.com/2009/12/helloworld_thumb.png?w=300&#038;h=218" alt="HelloWorld" width="300" height="218" align="right" border="0" /> The first sample app is <strong>HelloWorld</strong>. You can get it from the example apps download area.</p>
<p>It is a simple app, where you can enter text into a text field, click a button, and the text gets displayed in another text field.</p>
<p>Along the way, we do a few things that enable you to see how a Mac OS app is, or can be, quite different from an iOS app. Build your own app as you go through the sample app. Choose the &#8220;Cocoa Application&#8221; template, and don&#8217;t select any options for &#8220;document&#8221; or &#8220;Core Data&#8221;. Here are a few highlights of what you&#8217;ll experience:</p>
<p>Template contents: As you have learned, this kind of app includes an app delegate, a MainMenu nib, and little else. Open up the MainMenu nib, and you&#8217;ll see a &#8220;Window&#8221; object in the document window.</p>
<p>Controller class: To do some work, you&#8217;ll have to add a controller class. Click the Classes group, and add a new class. You will chose a &#8220;Cocoa Class&#8221;, specifically the &#8220;Objective-C class&#8221; (a subclass of NSObject). You will then add a reference to this new class in Interface Builder, by dragging an &#8220;NSObject&#8221; into the MainMenu nib&#8217;s document window, and setting its class name (to the name of the class you just created) on the Identity Inspector.</p>
<p>In your new class, you need to reference an NSTextField for the input area, another NSTextField for the output area, and a button. The text fields need to be marked with IBOutlet, and you&#8217;ll need to declare a method to handle the button click.</p>
<p>Back in Interface Builder, with the MainMenu.nib, add the two NSTextFields and the NSButton. Specifically:</p>
<ul>
<li>The &#8220;input area&#8221; NSTextField will be a multi-line wrapping NSTextField</li>
<li>The &#8220;output area&#8221; NSTextField will be a multi-line label NSTextField</li>
<li>The NSButton will be a &#8220;Push Button&#8221;</li>
</ul>
<p>To replicate the full functionality of the HelloWorld sample app, you&#8217;ll have to add in the parts for speech synthesis. The program code is well-documented, so look at it for what-when-where-why info.</p>
<p>An iOS app&#8217;s screen is a constant size, and we&#8217;re always working with a screen at a time. A Mac OS app can have a resizable window area. Our sample app anticipates this, by enabling the user to resize the window. Smooth resizing is implemented mostly in Interface Builder, by setting properties in the Size Inspector. Focus on looking in this inspector, and experiment with your own version of the app.</p>
<p>For a bit more fun, our sample app allows resizing only to the same height-width proportion as the background picture. To do this, we implement a delegate method that helps us.</p>
<p>.</p>
<p><strong>Information about user interface objects (controls)</strong></p>
<p>The iOS programmer will notice differences in AppKit user interface objects &#8211; e.g. buttons, text fields, and so on &#8211; that are conceptually related to UIKit objects. For best results, <em>do not assume</em> that an AppKit object has the same properties and instance methods as its related UIKit object. Also, when you look in the documentation for a class member, you may not find what you&#8217;re looking for. In that situation, follow the object inheritance hierarchy, and look in the object&#8217;s parent, repeating this action until you find what you&#8217;re looking for.</p>
<p>For example, an AppKit NSTextField has the following inheritance hierarchy:</p>
<ul>
<li>NSTextField inherits from&#8230;</li>
<li>NSControl, which inherits from&#8230;</li>
<li>NSView, which inherits from&#8230;</li>
<li>NSResponder, which inherits from&#8230;</li>
<li>NSObject</li>
</ul>
<p>To repeat, if you&#8217;re looking for a class member in NSTextField, and cannot find what you&#8217;re looking for, look in NSControl. Repeat with NSView etc. as required.</p>
<p>To help you get started working with text fields, note the following:</p>
<ul>
<li>To read the contents of an NSTextField, send the instance the &#8220;stringValue&#8221; message</li>
<li>To write the contents of an NSTextField, send the instance the &#8220;setStringValue&#8221; message</li>
</ul>
<p>.</p>
<h4>Professors sample app (&#8220;Professors base&#8221;)</h4>
<p><img style="display:inline;border:0 initial initial;margin:0 0 25px 25px;" title="ProfLoad" src="http://petermcintyre.files.wordpress.com/2009/12/profload_thumb.png?w=200&#038;h=333" alt="ProfLoad" width="200" height="333" align="right" border="0" /> The second sample app is Professors. You can download the base version (<strong>ProfessorsBase</strong>) from the example apps download area.</p>
<p>Your iOS apps often included UITableView based views. This Professors sample app uses a Mac OS NSTableView to display information about a list of professors.</p>
<p>While the iOS UITableView is a one-column table, an NSTableView enables the display of multiple columns. Each column can display text (the default), or other data types. For our simple example, we&#8217;ll stick with text display.</p>
<p>When we worked with an iOS UITableView, we implemented delegate and data source methods to handle table view operations. Although we could do that in a Mac OS app, we won&#8217;t &#8211; instead, we&#8217;ll use <strong>Cocoa Bindings</strong>, a Mac OS technology that can simplify table view operations. You&#8217;ll see that you can create a functional table view with little or no code.</p>
<p>.</p>
<h4>Introducing Cocoa Bindings</h4>
<p>Cocoa Bindings can simplify table view operations, and any other situation where you want to bind user interface objects to data model objects.</p>
<p>The data model objects can be simple &#8211; a string or an int for example &#8211; or they can be more complex and real-world &#8211; like an array, dictionary, or Core Data managed object graph. For best results, expose the data model object(s) as properties.</p>
<p>To introduce Cocoa Bindings, get the &#8220;Bound Slider&#8221; example app. It has a user interface with a slider and a text label. When the slider value changes, the text label is updated with the new value. The view controller has an int property, and both user interface objects are bound to the property. The Bindings Inspector enables you to establish the binding.</p>
<p>The following image illustrates the binding relationship:</p>
<p><img class="alignnone size-full wp-image-1357" title="Cocoa Bindings - bound slider" src="http://petermcintyre.files.wordpress.com/2010/03/bindingsslider_small.png?w=600" alt="Cocoa Bindings - bound slider"   /></p>
<p>While the example app and the diagram above shows you how to bind to a simple and distinct data model object (i.e. the int), you may also need to bind to a collection of objects, to display for example, a table view (as in today&#8217;s Professors&#8230; example apps).</p>
<p>For this scenario, Cocoa offers an Array Controller object. The Array Controller is added to the window nib, and a reference is made from it to your data model object, which in today&#8217;s example, is an array called &#8220;professors&#8221; in the view controller. The professors array is exposed as a property, and holds instances of &#8220;professor&#8221; objects as its elements.</p>
<p>Then, user interface objects are bound to the Array Controller, by specifying a &#8220;key path&#8221; to the data model object properties. Ideal for use with a table view, an Array Controller has an &#8220;arrangedObjects&#8221; instance variable, which represents the data model object collection (as a result of its reference to &#8211; in today&#8217;s example &#8211; the &#8220;professors&#8221; array in the view controller). The user interface object specifies the arrangedObjects instance variable, and then the property name in a data model object.</p>
<p>Alternatively, if the user interface object is to be bound to a specific object (rather than the whole collection), the Array Controller&#8217;s &#8220;selection&#8221; instance variable (inherited from NSArrayController&#8217;s superclass, NSObjectController) is the binding key. This scenario is used for one-of user interface elements, like a text label or an image.</p>
<p>The following image illustrates the binding relationship in the &#8220;Professors base&#8221; example app:</p>
<p><img class="alignnone size-full wp-image-1410" title="Cocoa Bindings - array controller" src="http://petermcintyre.files.wordpress.com/2010/03/bindingstableview_small2.png?w=600&#038;h=456" alt="Cocoa Bindings - array controller" width="600" height="456" /></p>
<p>.</p>
<h4>Continue working on the  &#8221;Professors base&#8221; app</h4>
<p>Now that you understand more about Cocoa Bindings, let&#8217;s continue building the app.</p>
<p>The first HelloWorld sample app was not a document-based application. Professors is, so as you&#8217;re following along, create a new Cocoa Application, and chose the &#8220;document&#8221; option. Notice that you get a MyDocument class and nib.</p>
<p>If you build and run, you will see that you get a fairly functional app from the template. You are able to create new (Command+N) document instances, close (Command+W) them, and so on. You can try saving (Command+S), but the save method hasn&#8217;t yet been implemented.</p>
<p>The next thing we want to do is to create a model class, &#8220;Professor&#8221;. This class will have properties for name, office, and photo. Nothing much is new here, when compared to the task in an iOS app. The class includes an init method overload that enables a fully working instance object to be returned.</p>
<p>Then, we will create an array that will be the data source for the table view. We do that in the MyDocument class. We configure it as a property, so that it will work with Cocoa Bindings.</p>
<blockquote><p><span style="color:#0000ff;">Note: the screen captures are from Xcode 3.x on Mac OS X 10.6.x. They are a bit out of date, but not much. Time permitting, they will be updated. </span></p></blockquote>
<p>.</p>
<p><img style="display:inline;border:0 initial initial;margin:0 0 25px 25px;" title="ProfBase1" src="http://petermcintyre.files.wordpress.com/2009/12/profbase1_thumb.png?w=200&#038;h=333" alt="ProfBase1" width="200" height="333" align="right" border="0" /> Now, we can create the user interface. It has two buttons (add a professor to the table view; delete a professor), a table view, and an image view (in which we&#8217;ll add photo support later). See the screen image on the right. On the window object&#8217;s Attributes Inspector, the &#8220;Resize&#8221; control has been unchecked/cleared, because we don&#8217;t want the user resizing the window.</p>
<p>After laying out the interface, do this: Drag an array controller from the library into the document window. On the Attributes Inspector, set the Class Name to &#8220;Professor&#8221;, and add the keys for the fullName, office, and photo properties. The keys match up to the model object&#8217;s properties, and are used by Cocoa Bindings. See the screen image below / to the left.</p>
<p><img style="display:inline;border:0 initial initial;margin:0 0 0 25px;" title="ProfBase2" src="http://petermcintyre.files.wordpress.com/2009/12/profbase2_thumb.png?w=200&#038;h=480" alt="ProfBase2" width="200" height="480" border="0" /></p>
<p>What did you just do? You added an array controller, and told it to work with &#8220;Professor&#8221; objects. In a minute, we&#8217;ll connect it to the &#8220;professors&#8221; array in the MyDocument class.</p>
<p><img style="display:inline;border:0 initial initial;margin:0 0 25px 25px;" title="ProfBase3" src="http://petermcintyre.files.wordpress.com/2009/12/profbase3_thumb.png?w=200&#038;h=480" alt="ProfBase3" width="200" height="480" align="right" border="0" /> An <strong>array controller</strong> manages a collection of objects in a situation where we use Cocoa Bindings. The Cocoa Bindings technologies do a number of things for us, including reducing code dependencies, and synchronizing views when model data changes (and vice-versa). The array controller is a helper object, similar in a way that the &#8220;fetched results controller&#8221; is a helper object in an iOS app that uses Core Data and a UITableView.</p>
<p>So, the array controller knows it is working with &#8220;Professor&#8221; objects. Let&#8217;s connect it to the &#8220;professors&#8221; array in the MyDocument class. Click the Bindings Inspector (green rectangle and circle). In the Controller Content area, bind to File&#8217;s Owner (i.e. the MyDocument class), and enter &#8220;professors&#8221; in the model key path dropdown list. The other properties are fine as they are. See the screen image to the right.</p>
<p>The final array controller configuration task is to connect the &#8220;add&#8221; and &#8220;delete&#8221; buttons. Click to show the Connections Inspector. In the Received Actions area, click-and-drag the &#8220;add:&#8221; outlet to the add button in the user interface. Click-and-drag the &#8220;remove:&#8221; outlet to the delete button in the user interface. Your inspector panel should look similar to the example below.</p>
<p><img style="display:inline;border:0 initial initial;margin:0 0 0 25px;" title="ProfBase8" src="http://petermcintyre.files.wordpress.com/2009/12/profbase8_thumb.png?w=200&#038;h=480" alt="ProfBase8" width="200" height="480" border="0" /></p>
<p>OK… now it&#8217;s time to connect the table view columns with the &#8220;Professor&#8221; properties fullName and office. Double-click the table view column for the professor&#8217;s name, and the window should look similar to the screen capture image below, on the left. Now, in the Bindings Inspector for that column, set these properties, so that they appear similar to the screen capture image below, on the right.</p>
<ul>
<li>Bind to Array Controller</li>
<li>Controller Key is arrangedObjects (which is the &#8220;professors&#8221; array we just pointed to above)</li>
<li>The Model Key Path is fullName (that&#8217;s what we want to show up in the table view column)</li>
</ul>
<p><img style="display:inline;border:0 initial initial;margin:0 0 0 25px;" title="ProfBase4" src="http://petermcintyre.files.wordpress.com/2009/12/profbase4_thumb.png?w=210&#038;h=350" alt="ProfBase4" width="210" height="350" border="0" /> <img style="display:inline;border:0 initial initial;" title="ProfBase5" src="http://petermcintyre.files.wordpress.com/2009/12/profbase5_thumb.png?w=146&#038;h=350" alt="ProfBase5" width="146" height="350" border="0" /></p>
<p>Continue by configuring the office column. Double-click the table view column for the professor&#8217;s office, and the window should look similar to the screen capture image below, on the left. Now, in the Bindings Inspector for that column, set these properties, so that they appear similar to the screen capture image below, on the right.</p>
<ul>
<li>Bind to Array Controller</li>
<li>Controller Key is arrangedObjects</li>
<li>The Model Key Path is office</li>
</ul>
<p><img style="display:inline;border:0 initial initial;margin:0 0 0 25px;" title="ProfBase6" src="http://petermcintyre.files.wordpress.com/2009/12/profbase6_thumb.png?w=210&#038;h=350" alt="ProfBase6" width="210" height="350" border="0" /> <img style="display:inline;border:0 initial initial;" title="ProfBase7" src="http://petermcintyre.files.wordpress.com/2009/12/profbase7_thumb.png?w=146&#038;h=350" alt="ProfBase7" width="146" height="350" border="0" /></p>
<p><img style="display:inline;border:0 initial initial;margin:0 0 25px 25px;" title="ProfBase9" src="http://petermcintyre.files.wordpress.com/2009/12/profbase9_thumb.png?w=200&#038;h=480" alt="ProfBase9" width="200" height="480" align="right" border="0" /> Save your work. At this point, you&#8217;ve configured an array controller helper object, and configured it to bind to the &#8220;professors&#8221; array. Run your app, and you will see that you can add and remove professors from the list.</p>
<p>The final thing we want to do with this app is to add the ability to drag-and-drop a professor&#8217;s photo into the image area of the app. It turns out to be easy to do. Click to select the image view. In its Bindings Inspector, set these properties, so that they appear similar to the screen capture image to the right.</p>
<ul>
<li>Bind to Array Controller</li>
<li>Controller Key is <strong>selection</strong> this time; we&#8217;re relying on a selected professor in the table view list</li>
<li>The Model Key Path is photo</li>
<li>Conditionally Sets Editable is checked</li>
</ul>
<p>Run your application again. Make sure you have created and selected (highlighted) a professor on your list. Now, open a Finder window that contains some photos, or a web page in Safari. Click, drag, and drop a photo into the image box on the app.</p>
<p>.</p>
<h4>Professors sample app, enhanced (&#8220;Professors save and load&#8221;)</h4>
<p>The third sample app extends Professors. You can download the enhanced version, ProfessorsSaveLoad, from the example apps download area.</p>
<p>As the name suggests, it adds the ability to save your list of professors as a document, and to load it up again.</p>
<p>We are going to use &#8220;archiving&#8221;, the same technology that we used on the iOS apps many weeks ago. To review, we have to configure the model class to know how to archive itself, and then we&#8217;ll implement methods in the controller that will take care of the saving and loading.</p>
<p>The first task is to edit the Professor .h interface to conform to the NSCoding protocol. Next, in its .m implementation, implement the initWithCoder: and encodeWithCoder: methods, as shown below.</p>
<p><img style="display:inline;border:0;margin:0 0 0 25px;" title="Code1" src="http://petermcintyre.files.wordpress.com/2009/12/code1.png?w=502&#038;h=245" alt="Code1" width="502" height="245" border="0" /></p>
<p>Next, we write some code for some existing MyDocument controller methods that we&#8217;ve ignored up to now.</p>
<p>The dataOfType:error: method implements saving. It runs when the user chooses &#8220;Save&#8221; from the File menu (or presses Command+S), provides a file name, and clicks the save button. To make it work, make it return an NSData as shown below:</p>
<p><img style="display:inline;border:0;margin:0 0 0 25px;" title="Code2" src="http://petermcintyre.files.wordpress.com/2009/12/code2.png?w=477&#038;h=32" alt="Code2" width="477" height="32" border="0" /></p>
<p>The readFromData:dataOfType:error method implements loading. It runs when the user chooses &#8220;Open&#8221; from the File menu (or presses Command+O), selects a file/document, and clicks the open button. To make it work, read (load) the data, place it into the &#8220;professors&#8221; property, and return YES, as shown below:</p>
<p><img style="display:inline;border:0;margin:0 0 0 25px;" title="Code3" src="http://petermcintyre.files.wordpress.com/2009/12/code3.png?w=452&#038;h=71" alt="Code3" width="452" height="71" border="0" /></p>
<p>Finally, we need to change some settings for the overall app that it and Mac OS will be able it to recognize the documents the app works with. Expand/open the &#8220;Targets&#8221; group, right-click the &#8220;Professors save and load&#8221; app, and choose Get Info. Click the Properties tab. This sheet enables us to configure information about the documents that this app works with. Here&#8217;s what to do. For more information, consult the reference documentation.</p>
<p>Near the top, change the &#8220;Identifier&#8221; to a unique identifier &#8211; use some of your name for this, and the last part will be the app&#8217;s name.</p>
<p>In the Document Types list, change the only entry, so that it has the following properties:</p>
<ul>
<li>Name &#8211; Professors document</li>
<li>Extensions &#8211; profs</li>
<li>OS Types &#8211; empty/blank/null</li>
</ul>
<p>Close the dialog box to save your changes. See below for a before and after view of this dialog box.</p>
<p>Before&#8230;</p>
<p><a href="http://petermcintyre.files.wordpress.com/2010/03/profload1.png"><img class="alignnone size-medium wp-image-1413" title="Target - file extension config" src="http://petermcintyre.files.wordpress.com/2010/03/profload1.png?w=300&#038;h=201" alt="Target - file extension config" width="300" height="201" /></a></p>
<p>After&#8230;</p>
<p><a href="http://petermcintyre.files.wordpress.com/2010/03/profload2.png"><img class="alignnone size-medium wp-image-1414" title="Target - file extension config" src="http://petermcintyre.files.wordpress.com/2010/03/profload2.png?w=300&#038;h=201" alt="Target - file extension config" width="300" height="201" /></a></p>
<p>Now, run your app. The save and load/open operations should work.</p>
<p>.</p>
<h4>Summary</h4>
<p>This Mac OS programming introduction has shown you some of the similarities with iOS programming, and it has highlighted a few interesting capabilities that are available only on Mac OS apps. Take your time reviewing today&#8217;s notes, and recreate the examples on your own.<br />
.</p>
<hr noshade="noshade" size="11" />
<p>.</p>
<p>.</p>
<p>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/petermcintyre.wordpress.com/4404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/petermcintyre.wordpress.com/4404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/petermcintyre.wordpress.com/4404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/petermcintyre.wordpress.com/4404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/petermcintyre.wordpress.com/4404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/petermcintyre.wordpress.com/4404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/petermcintyre.wordpress.com/4404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/petermcintyre.wordpress.com/4404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/petermcintyre.wordpress.com/4404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/petermcintyre.wordpress.com/4404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/petermcintyre.wordpress.com/4404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/petermcintyre.wordpress.com/4404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/petermcintyre.wordpress.com/4404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/petermcintyre.wordpress.com/4404/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=4404&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://petermcintyre.com/2011/12/06/intro-to-mac-os-cocoa-pgmg-for-ios-devs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d94ddb24521352b6287292b05c01323?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">petermcintyre</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2009/12/helloworld_thumb.png" medium="image">
			<media:title type="html">HelloWorld</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2009/12/profload_thumb.png" medium="image">
			<media:title type="html">ProfLoad</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2010/03/bindingsslider_small.png" medium="image">
			<media:title type="html">Cocoa Bindings - bound slider</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2010/03/bindingstableview_small2.png" medium="image">
			<media:title type="html">Cocoa Bindings - array controller</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2009/12/profbase1_thumb.png" medium="image">
			<media:title type="html">ProfBase1</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2009/12/profbase2_thumb.png" medium="image">
			<media:title type="html">ProfBase2</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2009/12/profbase3_thumb.png" medium="image">
			<media:title type="html">ProfBase3</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2009/12/profbase8_thumb.png" medium="image">
			<media:title type="html">ProfBase8</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2009/12/profbase4_thumb.png" medium="image">
			<media:title type="html">ProfBase4</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2009/12/profbase5_thumb.png" medium="image">
			<media:title type="html">ProfBase5</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2009/12/profbase6_thumb.png" medium="image">
			<media:title type="html">ProfBase6</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2009/12/profbase7_thumb.png" medium="image">
			<media:title type="html">ProfBase7</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2009/12/profbase9_thumb.png" medium="image">
			<media:title type="html">ProfBase9</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2009/12/code1.png" medium="image">
			<media:title type="html">Code1</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2009/12/code2.png" medium="image">
			<media:title type="html">Code2</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2009/12/code3.png" medium="image">
			<media:title type="html">Code3</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2010/03/profload1.png?w=300" medium="image">
			<media:title type="html">Target - file extension config</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2010/03/profload2.png?w=300" medium="image">
			<media:title type="html">Target - file extension config</media:title>
		</media:content>
	</item>
		<item>
		<title>SOAP XML Web Services on WCF – with EF data model</title>
		<link>http://petermcintyre.com/2011/12/02/soap-xml-web-svs-on-wcf-ef/</link>
		<comments>http://petermcintyre.com/2011/12/02/soap-xml-web-svs-on-wcf-ef/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 16:05:43 +0000</pubDate>
		<dc:creator>petermcintyre</dc:creator>
				<category><![CDATA[2011 Fall DPS907]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://petermcintyre.com/?p=4349</guid>
		<description><![CDATA[This post will teach you to add an Entity Framework data model to a WCF Service (SOAP XML Web Service). It is the second in a two-part series. This document was most recently updated in December 2011. . Introduction In the previous post, you learned how to create a simple SOAP XML Web Service, by using [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=4349&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post will teach you to add an Entity Framework data model to a WCF Service (SOAP XML Web Service).</p>
<p>It is the second in a two-part series. This document was most recently updated in December 2011.</p>
<p>.</p>
<h4>Introduction</h4>
<p>In the <a title="SOAP XML Web Services on WCF – introduction" href="http://petermcintyre.com/2011/11/30/soap-xml-web-services-on-wcf-introduction/">previous post</a>, you learned how to create a simple SOAP XML Web Service, by using the WCF Service item template. Here, you will learn how to add an Entity Framework data model to a service.</p>
<p>The scope of this post is modest. We will NOT be presenting a general-purpose <a href="http://en.wikipedia.org/wiki/N-tier" target="_blank">n-tier</a> approach. Part of the reason is that we cover this topic &#8211; SOAP XML Web Services &#8211; as a minor part of the overall course, in about three class and lab sessions.</p>
<p>We will, however, take advantage of the overall design and approach to modern SOAP XML Web Services development. The protocol and the standards, combined with the tooling, make it surprisingly easy to get good results with a reasonable amount of learning and effort.</p>
<p>.</p>
<h4>Configuration of our solution</h4>
<p>We will use a copy of the Northwind database in our solution.</p>
<p><img class="alignright size-full wp-image-4353" style="margin-left:25px;margin-bottom:10px;" title="Solution configuration" src="http://petermcintyre.files.wordpress.com/2011/12/solution-configuration.png?w=600" alt=""   />For this task, we will also organize our work by using &#8220;projects&#8221;. (In past tasks, we have used the &#8220;web site&#8221; as the container.) We need a project feature &#8211; the ability to easily hard-code a port number for the ASP.NET Development Server &#8211; to simplify our learning task.</p>
<p>The image to the right shows the desired result for this section of the post.</p>
<p>To get started, create a new project, which will simply be a solution &#8220;container&#8221;:</p>
<p>File &gt; New &gt; Project&#8230;</p>
<p>On the left-side navigator, under Installed Templates, choose:</p>
<p>Visual C# &gt; Other Project Types &gt; Visual Studio Solutions</p>
<p>In the center panel, choose Blank Solution. At the bottom of the dialog, enter an appropriate name (e.g. &#8220;WebServiceSolution&#8221;), and select a location (which will be a file system location).</p>
<p>The solution&#8217;s folder/directory will be a container for two projects:</p>
<ol>
<li>A web service</li>
<li>A client that will call the web service</li>
</ol>
<p>.</p>
<p>Continue by creating the <em>web service</em>. In Solution Explorer, right-click the solution, then choose Add &gt; New Project&#8230;</p>
<p>On the left-side navigator, under Installed Templates, choose Visual C#.</p>
<p>In the center panel, choose WCF Service Application. At the bottom of the dialog, enter an appropriate name (e.g. &#8220;WebService&#8221;), and make sure its location is the solution folder/directory from above.</p>
<p>Next, we need to configure a static port for the web service. This will ease our development process. Right-click the project, and choose Property Pages. On the Web tab, choose/select a fixed/static port. Save (Ctrl+S) your changes.</p>
<p>Continue by creating the <em>client</em>. In Solution Explorer, right-click the solution, then choose Add &gt; New Project&#8230;</p>
<p>On the left-side navigator, under Installed Templates, choose Visual C# &gt; Web.</p>
<p>In the center panel, choose ASP.NET Empty Web Application. At the bottom of the dialog, enter an appropriate name (e.g. &#8220;Requestor&#8221;), and make sure its location is the solution folder/directory from above.</p>
<p>Next, we should configure a static port for the client. As above, this will ease our development process. Right-click the project, and choose Property Pages. On the Web tab, choose/select a fixed/static port. Save (Ctrl+S) your changes.</p>
<p>Before continuing, compare your work to the image shown above. Build/compile, to make sure that there are no errors or warnings.</p>
<blockquote><p><span style="color:#ff0000;">Note about build/compile:</span></p>
<p><span style="color:#ff0000;">The build/compile step is important for a &#8220;project&#8221;. If you change your markup or your code, you <em>must</em> do a build/compile. If you don&#8217;t, your changes will not be implemented in the exe/dll. </span></p>
<p><span style="color:#ff0000;">This is different from a &#8220;web site&#8221;, which has a build/compile-on-demand feature.</span></p></blockquote>
<p>.</p>
<h4>Important WCF Service principles</h4>
<p>You have learned some basic principles of a WCF Service, and how it implements a SOAP XML Web Service:</p>
<ul>
<li>The &#8220;A&#8221; in &#8220;ABC&#8221;, address, is the publicly-accessible endpoint of your service.</li>
<li>The &#8220;B&#8221;, binding, is (obviously) HTTP, as a SOAP XML Web Service.</li>
<li>The &#8220;C&#8221;, contract is defined in the service interface, and implemented in the service class. A service contract will define the service&#8217;s operations, and a data contract will define the shape of the data that the service works with.</li>
</ul>
<p>.</p>
<p>There are a number of other principles that affect our design and coding decisions, covered next.</p>
<p>For custom types (e.g. our own types, and/or the types that describe the Northwind entities, like Product, Supplier, Category, etc.), you must define a data contract. This enables the serializer, DataContractSerializer, to do its work. A data contract requires you to mark a class with attributes.</p>
<p>If the type defines a circular reference, then the data contract attribute must be:</p>
<p>[DataContract(IsReference=true)]</p>
<p>However, the framework will also support <em>unmarked types</em>. This enables us to use POCO (Plain Old CLR Objects) types, such as those generated by the Entity Framework editor&#8217;s code generator.</p>
<p>To use POCO types with an Entity Framework data model, the entity names much match.</p>
<p>Each property must match up too (names and types). A property&#8217;s POCO type must be concrete (i.e. it cannot be an Interface). A property cannot use the &#8220;virtual&#8221; modifier.</p>
<p>Incidentally, for your information, the support for unmarked types is an example of &#8220;<a href="http://en.wikipedia.org/wiki/Convention_over_configuration" target="_blank">coding by convention</a>&#8220;. This software design paradigm is present in other areas of WCF Service development.</p>
<p>For best results, you must configure the context to disable (i.e. set to false) proxy generation, and lazy loading. (If you need eager loading, then use Include() in the query.)</p>
<p>In a client, when a Service Reference is created, the client has a definition of the web service class, and all of its operations. From the client&#8217;s perspective, return types can include:</p>
<ul>
<li>Scalar / primitive types</li>
<li>Generic dictionary</li>
<li>Entity types (more on this in the next section)</li>
<li>Collections, which are materialized as arrays (of&#8230; whatever type the web service sends)</li>
</ul>
<p>.</p>
<h4>Implementing these principles</h4>
<p>Now that the principles have been established, we can begin our implementation. Here is a preview of our work:</p>
<p>In the web service project, we will create an Entity Framework data model.</p>
<p>Next, we will generate entity classes. These classes must be edited, to follow the &#8220;unmarked types&#8221; principles above.</p>
<p>Then, we will define and implement service operations (i.e. methods).</p>
<p>In the client project, we will add a Service Reference. This will create a proxy of the web service. What&#8217;s interesting is that the client will have a definition for the web service class, and all of its operations, <em>and</em> it will have definitions for the entity types.</p>
<p>We emphasize here again: As a result of the Service Reference creation, the client will have definitions for the entity types. This will enable the client to work with instances (and collections) of entity types. Put another way, the client will be able to (for example) fetch a specific &#8220;Product&#8221; or &#8220;Employee&#8221;, enable the browser user to edit it, and return/save the changes, all while knowing the object&#8217;s properties and structure.</p>
<p>.</p>
<h4>Scope of our in-class efforts</h4>
<p>As noted above, we will work with a copy of the Northwind sample database. The Entity Framework data model will include three entities: Product, Category, Supplier.</p>
<p>The web service will include these operations:</p>
<ul>
<li>Return the number of products in the data store (as an integer)</li>
<li>Return a list of supplier names (as strings)</li>
<li>Return a collection of categories</li>
<li>Return a specific category</li>
<li>Accept and save an edited/changed category</li>
</ul>
<p>.</p>
<h4>Data model and generated classes</h4>
<p>In the web service project, create an Entity Framework data model. Include only these database tables in the data model:</p>
<ul>
<li>Products</li>
<li>Categories</li>
<li>Suppliers</li>
</ul>
<p>.</p>
<p>Build/compile your work before continuing. Note that you may have to use the NuGet Package Manager to get the EntityFramework package.</p>
<p>Next, generate entity classes. Use the DbContext generator. Note that you may have to download this generator template.</p>
<p>Then, edit the entity classes. Follow the &#8220;unmarked types&#8221; principles above:</p>
<ul>
<li>Properties must be concrete types (not interfaces)</li>
<li>Properties cannot be virtual</li>
</ul>
<p>.</p>
<p>Suggestion: The Category class includes a Picture property. In our example today, we will not need it. Therefore, mark that property with the [IgnoreDataMember] attribute.</p>
<p>(You can delete/remove the text templates &#8211; the .tt files &#8211; if you wish. If you need to re-generate your classes later, you can always do so.)</p>
<p>.</p>
<h4>Work on the web service</h4>
<p>As the comment suggests, you may want to re-factor your code, to change &#8220;Service1&#8243; to &#8220;Service&#8221; (i.e. without the digit &#8220;1&#8243;).</p>
<p>In your web service interface, define the service operations (methods).</p>
<p>Next, implement the methods in the web service class. Pay attention to the return types. Use the general approach and technique you used while working on your WCF Web API services.</p>
<p>Build/compile your work before continuing, and ensure that the results are clean (no errors or warnings). Run the service, to ensure that you see the service start page.</p>
<p>.</p>
<h4>Work on the client</h4>
<p>Add a Service Reference to the project. A suggested name is &#8220;RemoteService&#8221;. The process will create a namespace &#8211; RemoteService &#8211; and classes for the web service itself (ServiceClient), as well as the entity classes.</p>
<p>Add an ASP.NET Web Form (Default.aspx) to the project. You will use this page to show the results of web service requests, and/or as a launcher to other pages that do the work.</p>
<p>Build/compile your work before continuing, and ensure that the results are clean (no errors or warnings). View the page in a browser after you do this.</p>
<p>.</p>
<h4>Summary and wrap-up</h4>
<p>The .NET Framework, and Visual Studio, work together to enhance your productivity when creating a SOAP XML Web Service.</p>
<p>Get more practice by completing Lab 5.</p>
<p>.</p>
<hr noshade="noshade" size="11" />
<p>.</p>
<p>.</p>
<p>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/petermcintyre.wordpress.com/4349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/petermcintyre.wordpress.com/4349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/petermcintyre.wordpress.com/4349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/petermcintyre.wordpress.com/4349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/petermcintyre.wordpress.com/4349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/petermcintyre.wordpress.com/4349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/petermcintyre.wordpress.com/4349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/petermcintyre.wordpress.com/4349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/petermcintyre.wordpress.com/4349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/petermcintyre.wordpress.com/4349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/petermcintyre.wordpress.com/4349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/petermcintyre.wordpress.com/4349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/petermcintyre.wordpress.com/4349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/petermcintyre.wordpress.com/4349/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=4349&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://petermcintyre.com/2011/12/02/soap-xml-web-svs-on-wcf-ef/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d94ddb24521352b6287292b05c01323?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">petermcintyre</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2011/12/solution-configuration.png" medium="image">
			<media:title type="html">Solution configuration</media:title>
		</media:content>
	</item>
		<item>
		<title>SOAP XML Web Services on WCF &#8211; introduction</title>
		<link>http://petermcintyre.com/2011/11/30/soap-xml-web-services-on-wcf-introduction/</link>
		<comments>http://petermcintyre.com/2011/11/30/soap-xml-web-services-on-wcf-introduction/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 13:31:04 +0000</pubDate>
		<dc:creator>petermcintyre</dc:creator>
				<category><![CDATA[2011 Fall DPS907]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://petermcintyre.com/?p=4322</guid>
		<description><![CDATA[This post will introduce you to SOAP XML Web Services on WCF. It is the first in a two-part series. This post uses an in-memory (per-instance) data store. The next post will use a persistent data store, accessed through the Entity Framework. This document was most recently updated in November 2011. . Introduction At this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=4322&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post will introduce you to SOAP XML Web Services on WCF.</p>
<p>It is the first in a two-part series. This post uses an in-memory (per-instance) data store. The next post will use a persistent data store, accessed through the Entity Framework.</p>
<p>This document was most recently updated in November 2011.</p>
<p>.</p>
<h4>Introduction</h4>
<p>At this point in the semester, you have some experience with one of the two styles of web services, RESTful. SOAP XML Web Services is the other style that you&#8217;ll encounter. Here are some key ideas that will help you get oriented with SOAP XML Web Services:</p>
<ul>
<li>The plain-text data interchange format is XML</li>
<li>The XML conforms to SOAP</li>
<li>Often, a SOAP XML Web Service is published on a single (URL) endpoint</li>
<li>The service includes one or more methods; each method may accept parameters, and may return data</li>
<li>Service discovery is built in to the specification/standard</li>
<li>Requestors use GET or POST requests to interact with the web service</li>
<li>Requestors can use the service discovery feature to create a proxy class that models the web service (in fact, this is typical with most programming platforms)</li>
</ul>
<p>.</p>
<p>On the Microsoft Web Platform, WCF technology is used to create SOAP XML Web Services. Version 4 of the .NET Framework improved the design and coding experience, and we will use version 4 in this two-part series. Scan the following article, and read about the WCF and web services topics:</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ee354381.aspx" target="_blank">What&#8217;s new in WCF 4</a> article</p>
<p>FYI &#8211; legacy versions of the Microsoft Web Platform used &#8220;asmx&#8221; item types to host SOAP XML Web Services. They were easy to create, but they were a solution for a very limited set of use cases. Do not use &#8220;asmx&#8221; item types for new web services. Scan the following article to read about the differences:</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ff648181.aspx" target="_blank">Legacy info</a> on the difference between asmx and wcf web services</p>
<p>.</p>
<h4>What is a WCF Service?</h4>
<p>In Visual Studio 2010, a SOAP XML Web Service is created as a WCF Service. The following will introduce WCF Service concepts and topics.</p>
<p>A WCF Service is a program that exposes one or more endpoints, each of which exposes one or more service operations.</p>
<p>An endpoint specifies:</p>
<ol>
<li>An address where the service can be found (e.g. http://host.domain.com/contacts.svc)</li>
<li>A binding that tells the client how to communicate with the service (e.g. HTTP)</li>
<li>A contract that defines the service&#8217;s functionality (e.g. it will do &#8220;this task&#8221; and &#8220;that task&#8221;)</li>
</ol>
<p>.</p>
<h4>Creating a WCF Service</h4>
<p>You create a WCF Service in Visual Studio 2010. It is an (item type) that you can add to a Project or a Web Site.</p>
<blockquote><p>A Web Site is software and resources that you create in a specific folder/directory. A Web Site must be hosted on a web server (e.g. either the ASP.NET Development Server, or a Microsoft Web Platform server). You can deploy a Web Site using a simple copy operation. The web server will compile and execute an endpoint upon request.</p></blockquote>
<p>.</p>
<blockquote><p>A Project is software and resources that you create in a specific folder/directory. A Project can be hosted on a web server, or on another kind of host (e.g. an executable, or a Windows Service). You must compile (build) the project (which creates an executable, either a dll or an exe) before you deploy it.</p></blockquote>
<p>.</p>
<p>The default WCF Service item type (that you create with Visual Studio 2010) will create three software objects:</p>
<p>1. A publicly-accessible endpoint</p>
<p>2. A C# code-behind for the (above) publicly-accessible endpoint, which implements…</p>
<p>3. A C# interface that describes the “service contract” and “service operations”</p>
<p>.</p>
<p>The following sections include important information about each object.</p>
<p>.</p>
<p><strong>Publicly-accessible endpoint</strong></p>
<p>You pick the name (e.g. &#8220;Contacts&#8221;), it adds a “svc” extension (e.g. &#8220;Contacts.svc&#8221;).</p>
<p>You don’t add code to this endpoint.</p>
<p>.</p>
<p><strong>C# code-behind for the (above) publicly-accessible endpoint</strong></p>
<p>This code file is located in the App_Code folder/directory.</p>
<p>For example, continuing to use the name above, it will be called &#8220;Contacts.cs&#8221;.</p>
<p>.</p>
<p><strong>C# interface that describes the “service contract” and “service operations”</strong></p>
<p>A &#8220;service contract&#8221; is an agreement to define and provide a number of &#8220;service operations&#8221;. An interface is used as the code container for both. By convention in the .NET Framework, an interface name begins with an upper-case letter &#8220;I&#8221;. The second letter is also upper-case.</p>
<p>For example, continuing to use the name above, the interface will be called &#8220;IContacts.cs&#8221;.</p>
<p>Each &#8220;service operation&#8221; is a method. The method will have a return value, and a parameter list.</p>
<p>Although not required, it is a best practice to use an interface to declare the &#8220;service contract&#8221; and &#8220;service operations&#8221;.</p>
<p>What is the relationship between the interface and the (class) implementation?</p>
<ul>
<li>The interface defines the service&#8217;s methods.</li>
<li>The implementation contains code for these methods.</li>
</ul>
<p>.</p>
<h4>Method return values and parameters</h4>
<p>As noted earlier, a method will have a return value, and a parameter list.</p>
<p>The types must be serializable (obviously).</p>
<p>Primitive types are serializable <em>by default</em>. Many other types in the .NET Framework are also serializable by default.</p>
<p>If you create your own types (e.g. Product, Supplier, Contact, Address, Customer, etc.), then you typically &#8220;mark&#8221; your types (with &#8220;attributes&#8221;) to define a &#8220;data contract&#8221;.</p>
<p>A &#8220;data contract&#8221; is an agreement to define and provide a number of &#8220;data members&#8221;. The default WCF Service item type adds the &#8220;data contract&#8221; to the interface code container.</p>
<p>For example, continuing to use the name above, it will be added to &#8220;IContacts.cs&#8221;.</p>
<p>Each type is a class (as it always is). You typically add the [DataContract] attribute to the class.</p>
<p>Public properties are used to define the publicly-accessible data members.</p>
<p>Each serializable property gets the [DataMember] attribute.</p>
<p>.</p>
<h4>Creating a client requestor</h4>
<p>When working on RESTful web services earlier in the semester, you learned that you could interact with your web service by using a browser, or an HTTP requestor like your Lab 1, Fiddler, or your service&#8217;s HTTP Test Client.</p>
<p>With SOAP XML Web Services, some of the same techniques can be used. However, the message packaging format is SOAP XML, which can be inconvenient to manually enter into a request.</p>
<p>Another approach is to create a client requestor. Conceptually, it will be similar to your Lab 1, because it will be able to make a request to the web service, and receive (and process) the response. That&#8217;s what we&#8217;ll do here, by creating an ASP.NET Web Forms client requestor.</p>
<p>The key concept is to create a proxy, which will &#8220;model&#8221; the web service. Visual Studio has built-in tooling for this. Right-click the (web site) root, and select &#8220;Add Service Reference&#8221;. This will enable you to connect to the web service, discover its functionality, and have Visual Studio create a local proxy of your web service&#8217;s classes.</p>
<p>Then, in your web form code-behind, you simply 1) create an instance of the proxy, and 2) call its methods.</p>
<p>.</p>
<h4>On your own &#8211; create a web service, and a client requestor</h4>
<p>Your task:</p>
<p>In a new empty web site, create a service with two methods.</p>
<p>Method 1 will simply return your name (firstname last name) as a string.</p>
<p>Method 2 will return a collection (of strings) of your current-semester Seneca course codes (e.g. WSA500, SYS566, etc.).</p>
<p>In another new empty web site, create a (Default.aspx) web form that will call and display the data from the web service. Use Label web server controls for the data.</p>
<p>.</p>
<h4>Preview of the topics we&#8217;ll cover in the next lecture</h4>
<p>A blogger&#8217;s two-part series:</p>
<p><a href="http://www.toplinestrategies.com/dotneters/net/wcf-entity-framework-and-n-tier-solutions-part-2/?lang=en" target="_blank">service create</a>, and <a href="http://www.toplinestrategies.com/dotneters/net/wcf-entity-framework-and-n-tier-solutions-%E2%80%93-part-3/" target="_blank">service consume</a> (from Silverlight)</p>
<p><a href="http://www.codeproject.com/KB/WCF/WCFandEF.aspx" target="_blank">Another blogger&#8217;s article</a>, some ideas are OK</p>
<p>Another blogger&#8217;s article on &#8220;<a href="http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_interrfaces03052006095933AM/csharp_interrfaces.aspx" target="_blank">what is an interface</a>&#8220;</p>
<p>WCF and EF on StackOverflow - <a href="http://stackoverflow.com/questions/586297/wcf-contracts-from-entity-framework" target="_blank">data contracts</a></p>
<p>.</p>
<h4>Reference articles</h4>
<p><a href="http://msdn.microsoft.com/en-ca/vstudio/hh341490" target="_blank">Learn C#</a> page</p>
<p><a href="http://msdn.microsoft.com/en-ca/library/ms173156.aspx" target="_blank">Interfaces</a> - C# Programming Guide</p>
<p><a href="http://msdn.microsoft.com/en-ca/library/ms173149.aspx" target="_blank">Inheritance</a> - C# Programming Guide</p>
<p><a href="http://msdn.microsoft.com/library/orm-9780596521066-01-03.aspx" target="_blank">C# Language Fundamentals</a></p>
<p>.</p>
<hr noshade="noshade" size="11" />
<p>.</p>
<p>.</p>
<p>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/petermcintyre.wordpress.com/4322/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/petermcintyre.wordpress.com/4322/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/petermcintyre.wordpress.com/4322/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/petermcintyre.wordpress.com/4322/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/petermcintyre.wordpress.com/4322/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/petermcintyre.wordpress.com/4322/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/petermcintyre.wordpress.com/4322/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/petermcintyre.wordpress.com/4322/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/petermcintyre.wordpress.com/4322/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/petermcintyre.wordpress.com/4322/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/petermcintyre.wordpress.com/4322/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/petermcintyre.wordpress.com/4322/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/petermcintyre.wordpress.com/4322/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/petermcintyre.wordpress.com/4322/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=4322&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://petermcintyre.com/2011/11/30/soap-xml-web-services-on-wcf-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d94ddb24521352b6287292b05c01323?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">petermcintyre</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating sequence diagrams</title>
		<link>http://petermcintyre.com/2011/10/31/creating-sequence-diagrams/</link>
		<comments>http://petermcintyre.com/2011/10/31/creating-sequence-diagrams/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 14:26:41 +0000</pubDate>
		<dc:creator>petermcintyre</dc:creator>
				<category><![CDATA[2011 Fall DPS907]]></category>
		<category><![CDATA[2011 Fall DPS913]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iOS Cocoa Touch]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://petermcintyre.com/?p=4147</guid>
		<description><![CDATA[In this document, we briefly describe a few different ways to create sequence diagrams. This post was most recently updated in October 2011. It is intended for programmers in a degree-level academic program that focuses on software development. This post will likely be updated a few times in the near future, to add more detail [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=4147&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this document, we briefly describe a few different ways to create sequence diagrams.</p>
<p>This post was most recently updated in October 2011. It is intended for programmers in a degree-level academic program that focuses on software development. This post will likely be updated a few times in the near future, to add more detail and information.</p>
<p>.</p>
<h4>A brief survey of sequence diagram creation toolsets</h4>
<p>Students in Seneca&#8217;s ICT software development programs learn to use Rational Rose to create sequence diagrams, and other software system design modeling assets.</p>
<p>Visual 2010 Ultimate Edition now includes tooling that enables the creation of sequence diagrams.</p>
<p>Online, there are many tools that are offered, in both free and pay-for versions. In the following section, we&#8217;ll look at one of these tools.</p>
<p>.</p>
<h4>Websequencediagrams.com</h4>
<p>Websequencediagrams.com is an online tool that enables you to create and save sequence diagrams. Its syntax is easy and discoverable. It enables you to save your work in a PNG image, a PDF, or as source text. It also provides online tooling, via an API.</p>
<p>A recent post by the author (<a title="Web service security principles – OAuth 2.0 example" href="http://petermcintyre.com/2011/10/30/web-svc-security-principles-oauth/">Web service security principles – OAuth 2.0 example</a>) included two sequence diagrams.</p>
<p>The source text for the first diagram is below:</p>
<p><a href="http://petermcintyre.files.wordpress.com/2011/10/sequence-diagram-for-first-request3.png"><img class="alignnone size-full wp-image-4122" title="Sequence diagram for first request" src="http://petermcintyre.files.wordpress.com/2011/10/sequence-diagram-for-first-request3.png?w=600&#038;h=442" alt="" width="600" height="442" /></a></p>
<p>.</p>
<p><pre class="brush: plain;">
participant Resource\nOwner as RO
participant &quot;Web\nBrowser&quot; as ClientUI
participant Client\nApp as Client
participant Authorization\nServer as AS
participant Resource\nServer as RS

RO-&gt;ClientUI: [1] want protected resource
activate RO
activate ClientUI

ClientUI-&gt;Client: [2] GET protected resource
activate Client

Client--&gt;ClientUI: [3] HTTP 302 redirect
deactivate Client
deactivate ClientUI

ClientUI-&gt;AS: [4] GET authentication UI
activate ClientUI
activate AS
AS--&gt;ClientUI: [5] respond with authentication UI

ClientUI--&gt;RO: [6] view authentication UI

RO-&gt;ClientUI: [7] enter credentials
ClientUI-&gt;AS: [8] POST the credentials

AS--&gt;ClientUI: [9] HTTP 302 redirect to redirection endpoint
deactivate AS
deactivate ClientUI

ClientUI-&gt;Client: [10] GET auth grant exchanged
activate ClientUI
activate Client

Client-&gt;AS: [11] POST request access token
activate AS

AS--&gt;Client: [12] respond with access token
deactivate AS

Client--&gt;ClientUI: [13] HTTP 302 redirect
deactivate Client
deactivate ClientUI

ClientUI-&gt;Client: [14] GET protected resource
activate Client
activate ClientUI

Client-&gt;RS: [15] GET protected resource (with access token)
activate RS

RS--&gt;Client: [16] respond with the resource
deactivate RS

Client--&gt;ClientUI: [17] render resource in browser

deactivate Client
ClientUI--&gt;RO: [18] view the resource
deactivate ClientUI

deactivate RO
</pre></p>
<p>.</p>
<p>The source text for the second diagram is below:</p>
<p><a href="http://petermcintyre.files.wordpress.com/2011/10/sequence-diagram-for-subsequent-requests1.png"><img class="alignnone size-full wp-image-4123" title="Sequence diagram for subsequent requests" src="http://petermcintyre.files.wordpress.com/2011/10/sequence-diagram-for-subsequent-requests1.png?w=600&#038;h=217" alt="" width="600" height="217" /></a></p>
<p>.</p>
<p><pre class="brush: plain;">
participant Resource\nOwner as RO
participant &quot;Web\nBrowser&quot; as ClientUI
participant Client\nApp as Client
participant Authorization\nServer as AS
participant Resource\nServer as RS

RO-&gt;ClientUI: [1] want protected resource
activate RO
activate ClientUI

ClientUI-&gt;Client: [2] GET protected resource
activate Client

Client-&gt;RS: [15] GET protected resource (with access token)
activate RS

RS--&gt;Client: [16] respond with the resource
deactivate RS

Client--&gt;ClientUI: [17] render resource in browser

deactivate Client
ClientUI--&gt;RO: [18] view the resource
deactivate ClientUI

deactivate RO
</pre></p>
<p>.</p>
<hr noshade="noshade" size="11" />
<p>.</p>
<p>.</p>
<p>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/petermcintyre.wordpress.com/4147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/petermcintyre.wordpress.com/4147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/petermcintyre.wordpress.com/4147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/petermcintyre.wordpress.com/4147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/petermcintyre.wordpress.com/4147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/petermcintyre.wordpress.com/4147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/petermcintyre.wordpress.com/4147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/petermcintyre.wordpress.com/4147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/petermcintyre.wordpress.com/4147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/petermcintyre.wordpress.com/4147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/petermcintyre.wordpress.com/4147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/petermcintyre.wordpress.com/4147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/petermcintyre.wordpress.com/4147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/petermcintyre.wordpress.com/4147/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=4147&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://petermcintyre.com/2011/10/31/creating-sequence-diagrams/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d94ddb24521352b6287292b05c01323?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">petermcintyre</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2011/10/sequence-diagram-for-first-request3.png" medium="image">
			<media:title type="html">Sequence diagram for first request</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2011/10/sequence-diagram-for-subsequent-requests1.png" medium="image">
			<media:title type="html">Sequence diagram for subsequent requests</media:title>
		</media:content>
	</item>
		<item>
		<title>Brief introduction to securing a WCF Web API service with an access token</title>
		<link>http://petermcintyre.com/2011/10/30/intro-wcf-web-api-with-access-token/</link>
		<comments>http://petermcintyre.com/2011/10/30/intro-wcf-web-api-with-access-token/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 20:54:14 +0000</pubDate>
		<dc:creator>petermcintyre</dc:creator>
				<category><![CDATA[2011 Fall DPS907]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://petermcintyre.com/?p=4127</guid>
		<description><![CDATA[This post is a brief introduction to securing a WCF Web API service with an access token. This document was most recently updated in October 2011. It is intended to be used by entry-level web service programmers. . Overview of the scenario Token-based schemes are often used for web services that require security. Recently, in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=4127&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post is a brief introduction to securing a WCF Web API service with an access token.</p>
<p>This document was most recently updated in October 2011. It is intended to be used by entry-level web service programmers.</p>
<p>.</p>
<h4>Overview of the scenario</h4>
<p>Token-based schemes are often used for web services that require security. Recently, in class/lecture, we described many of the relevant security principles, and the implementation components, using the OAuth 2.0 Authorization Protocol as an example.</p>
<p>This post includes code that illustrates the bare essentials of handling an access token.</p>
<p>Warning &#8211; The code below is NOT a reference sample, or a best practice example. It simply illustrates the concept, in a clearly-understandable manner. Also, it does NOT deal with authentication and authorization issues, authorization stores, or the other &#8220;moving parts&#8221; that a full and complete solution includes.</p>
<p>.</p>
<h4>Sample service code</h4>
<p>Use your template to create a new WCF Web API service. Code the service class as follows:</p>
<p><pre class="brush: csharp;">

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
// Web service namespaces
using System.ServiceModel;
using System.ServiceModel.Web;
// Additional namespaces
using System.Net;
using System.Net.Http;
using Microsoft.ApplicationServer.Http.Dispatcher;
using System.Net.Http.Headers;

[ServiceContract]
public class Operations
{
    // Custom authorization token
    public string customToken { get; set; }

    // Collection of access tokens, which will be an in-memory &quot;authorization store&quot;
    protected List&lt;string&gt; AccessTokenStore;

    // Constructor
    public Operations()
    {
        this.customToken = HttpContext.Current.Request.Headers[&quot;X-ICTtoken&quot;];

        // Un-comment the following if you want to protect the whole service
        //if (this.customToken != &quot;whatever&quot;)
        //    throw new HttpResponseException(HttpStatusCode.Forbidden);

        // Create an in-memory &quot;authorization store&quot;, with a few access tokens
        AccessTokenStore = new List&lt;string&gt;();
        AccessTokenStore.Add(&quot;triUt6ustoeQ&quot;);
        AccessTokenStore.Add(&quot;KOEn4Ejouqle&quot;);
        AccessTokenStore.Add(&quot;rIuv5u7hoeno&quot;);
        AccessTokenStore.Add(&quot;y7UcIeJ9eCIa&quot;);
        AccessTokenStore.Add(&quot;Joestievief9&quot;);
    }

    // Remove this method from an in-production (deployed) web service
    [WebGet(UriTemplate = &quot;&quot;)]
    public string ServiceRoot()
    {
        return &quot;Append /test to the URI to use the HTTP Test Client&quot;;
    }

    [WebGet(UriTemplate = &quot;example1&quot;)]
    public List&lt;string&gt; Example1(HttpRequestMessage request)
    {
        // Get the authorization header
        AuthenticationHeaderValue auth = request.Headers.Authorization;
        // The scheme should be &quot;Bearer&quot;, and the parameter should be the access token

        if (auth == null)
        {
            throw new HttpResponseException(HttpStatusCode.Unauthorized);
        }
        else
        {
            // Create a response object
            List&lt;string&gt; response = new List&lt;string&gt;();
            // Report the results
            response.Add(&quot;The authorization scheme was: &quot; + auth.Scheme);
            response.Add(&quot;The parameter was: &quot; + auth.Parameter);

            // Check if the access token is in the store
            if (AccessTokenStore.Find(t =&gt; t == auth.Parameter) == null)
            {
                response.Add(&quot;The access token was NOT FOUND in the authorization store&quot;);
            }
            else
            {
                response.Add(&quot;This is a valid access token&quot;);
            }

            return response;
        }
    }

}
</pre></p>
<p>.</p>
<h4>Test your service</h4>
<p>Run the HTTP Test Client for the service.</p>
<p>Request the &#8220;example1&#8243; URI. It should respond with 401 unauthorized.</p>
<p>Now, add an &#8220;authorization header&#8221;:</p>
<p>Authorization:Basic foobar</p>
<p>The response should appear as follows:</p>
<p><pre class="brush: xml;">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;ArrayOfString xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
  &lt;string&gt;The authorization scheme was: Basic&lt;/string&gt;
  &lt;string&gt;The parameter was: foobar&lt;/string&gt;
  &lt;string&gt;The access token was NOT FOUND in the authorization store&lt;/string&gt;
&lt;/ArrayOfString&gt;

</pre></p>
<p>.</p>
<p>Next, change the authorization header:</p>
<p>Authorization:Bearer rIuv5u7hoeno</p>
<p>(or one of the valid authorization codes)</p>
<p>The response should appear as follows:</p>
<p><pre class="brush: xml;">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;ArrayOfString xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
  &lt;string&gt;The authorization scheme was: Bearer&lt;/string&gt;
  &lt;string&gt;The parameter was: rIuv5u7hoeno&lt;/string&gt;
  &lt;string&gt;This is a valid access token&lt;/string&gt;
&lt;/ArrayOfString&gt;

</pre></p>
<p>.</p>
<hr noshade="noshade" size="11" />
<p>.</p>
<p>.</p>
<p>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/petermcintyre.wordpress.com/4127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/petermcintyre.wordpress.com/4127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/petermcintyre.wordpress.com/4127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/petermcintyre.wordpress.com/4127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/petermcintyre.wordpress.com/4127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/petermcintyre.wordpress.com/4127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/petermcintyre.wordpress.com/4127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/petermcintyre.wordpress.com/4127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/petermcintyre.wordpress.com/4127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/petermcintyre.wordpress.com/4127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/petermcintyre.wordpress.com/4127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/petermcintyre.wordpress.com/4127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/petermcintyre.wordpress.com/4127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/petermcintyre.wordpress.com/4127/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=4127&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://petermcintyre.com/2011/10/30/intro-wcf-web-api-with-access-token/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d94ddb24521352b6287292b05c01323?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">petermcintyre</media:title>
		</media:content>
	</item>
		<item>
		<title>Web service security principles &#8211; OAuth 2.0 example</title>
		<link>http://petermcintyre.com/2011/10/30/web-svc-security-principles-oauth/</link>
		<comments>http://petermcintyre.com/2011/10/30/web-svc-security-principles-oauth/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 19:04:26 +0000</pubDate>
		<dc:creator>petermcintyre</dc:creator>
				<category><![CDATA[2011 Fall DPS907]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://petermcintyre.com/?p=4096</guid>
		<description><![CDATA[This post discusses web service security principles, using the OAuth 2.0 Authorization Protocol. This document was most recently updated in October, 2011. It is intended for entry-level web service programmers. . Introduction to the scenarios This post describes the use of a web service to deliver resources to requestors. The web service&#8217;s resources will be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=4096&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post discusses web service security principles, using the OAuth 2.0 Authorization Protocol.</p>
<p>This document was most recently updated in October, 2011. It is intended for entry-level web service programmers.</p>
<p>.</p>
<h4>Introduction to the scenarios</h4>
<p>This post describes the use of a web service to deliver resources to requestors. The web service&#8217;s resources will be protected, and requestors must use the OAuth 2.0 Authorization Protocol.</p>
<p>A separate client app, perhaps an ASP.NET Web Forms app, would be used to request resources from the web service. Users of the client app will be able to request their own resources after authenticating.</p>
<p>The first scenario covers the use case where a <strong>client app</strong>, which does not yet have a valid <em>access token</em>, requests a protected resource.</p>
<p>The second scenario covers the use case where a <strong>client app</strong>, which has a valid <em>access token</em>, requests a protected resource.</p>
<p>.</p>
<h4>OAuth 2.0 Authorization Protocol information</h4>
<p>The OAuth 2.0 Autorization Protocol is described in <a href="http://datatracker.ietf.org/doc/draft-ietf-oauth-v2/" target="_blank">draft-ietf-oauth-v2-22</a>.</p>
<p>As suggested by its name, it is an Internet-Draft specification. As noted in the document:</p>
<blockquote><p>It is inappropriate to use Internet-Drafts as reference material or to cite them other than as &#8220;work in progress&#8221;.</p></blockquote>
<p>Accordingly, in this post, we will use it as &#8220;working document&#8221; to enable security on a web service.</p>
<p>OAuth defines four roles:</p>
<ol>
<li><strong>Resource owner</strong> &#8211; An entity (e.g. an end user) capable of granting access to a protected resource.</li>
<li><strong>Resource server</strong> &#8211; A server that hosts a protected resource. It responds to requests by validating an access token.</li>
<li>Client &#8211; Also known as a <strong>client app</strong>, this is an application that makes requests for a protected resource, on behalf of the resource owner, and with its authorization.</li>
<li><strong>Authorization server</strong> &#8211; A server that authenticates resource owners, client apps, and issues access tokens.</li>
</ol>
<p>.</p>
<p>OAuth is a protocol that enables a client app to use an access token to request a protected resource. The access token is issued to the client app by an authorization server, with the approval of the resource owner.</p>
<p>There are two defined client app types:</p>
<ol>
<li>Confidential &#8211; Capable of maintaining confidentiality of client app credentials.</li>
<li>Public &#8211; Incapable of maintaining confidentiality of client app credentials.</li>
</ol>
<p>.</p>
<p>There are four defined flows or scenarios that enable a resource owner to authorize the issuance of an access token:</p>
<ol>
<li>Authorization code &#8211; A resource owner is able to authenticate directly with an authorization server, and passes on an &#8220;authorization code&#8221; to the client app.</li>
<li>Implicit &#8211; For client apps which are implemented in a browser using a scripting language (such as JavaScript).</li>
<li>Resource owner password credentials &#8211; Where there is a high degree of trust between the resource owner and the client app (e.g. a trusted client app on a resource owner&#8217;s mobile device).</li>
<li>Client credentials &#8211; For access to protected resources that are under the control of the client app (and not any specific/individual resource owner).</li>
</ol>
<p>.</p>
<p>This post will cover the first flow/scenario, &#8220;authorization code&#8221;, with a &#8220;confidential&#8221; client.</p>
<p>.</p>
<h4>Scenario terminology and assumptions</h4>
<p>This post uses terminology from the OAuth spec, plus the following:</p>
<p>UI = user interface</p>
<p>Web browser = an HTTP requestor application that renders HTML content</p>
<p>Client app = web app, an executable that runs on a web server</p>
<p>.</p>
<p>The following diagram is a high-level overview of the components.</p>
<p><img class="alignnone size-full wp-image-4110" title="Web service as a resource server" src="http://petermcintyre.files.wordpress.com/2011/10/web-service-as-a-resource-server.png?w=600&#038;h=383" alt="" width="600" height="383" /></p>
<p>.</p>
<p>The authorization server and the resource server share an authorization store. The authorization store holds the following kinds of information collections:</p>
<ul>
<li><em>resource owner credentials</em></li>
<li><em>client app credentials</em> (which has a <em>client app identifier</em> that will be used by the web browser)</li>
<li><em>authorization grant</em> (which has a limited lifetime and scope)</li>
<li><em>access token</em> (which has a limited lifetime and scope)</li>
</ul>
<p>.</p>
<p>For the following scenarios, the reader can assume that the resource owner credentials and the client app credentials already exist. Further, the authorization server has the programming, UI, and endpoints that enable the maintenance of these credentials.</p>
<p>The reader can also assume that the authorization server has the programming, UI, and endpoints that enable the maintenance of authorization grants and access tokens.</p>
<p>.</p>
<h4>Scenario &#8211; first request for a protected resource</h4>
<p>This scenario covers the use case where a <strong>client app</strong>, which does not yet have a valid <em>access token</em>, requests a protected resource.</p>
<p>This scenario is documented on a sequence diagram, shown below. Each signal is identified with a number in square brackets, [#], and you will find them in the text that follows.</p>
<p><a href="http://petermcintyre.files.wordpress.com/2011/10/sequence-diagram-for-first-request3.png"><img class="alignnone size-full wp-image-4122" title="Sequence diagram for first request" src="http://petermcintyre.files.wordpress.com/2011/10/sequence-diagram-for-first-request3.png?w=600&#038;h=442" alt="" width="600" height="442" /></a></p>
<p>.</p>
<blockquote><p><span style="color:#008000;">How was this sequence diagram created? <strong><a title="Creating sequence diagrams" href="http://petermcintyre.com/2011/10/31/creating-sequence-diagrams/"><span style="color:#008000;">Click here and read this post</span></a></strong> for details. </span></p></blockquote>
<p>.</p>
<p>A <strong>resource owner</strong>, using a <strong>web browser</strong>, begins interacting with content in a <strong>client app</strong>. This begins a new &#8220;session&#8221; between the <strong>resource owner</strong>&#8216;s user-agent (the <strong>web browser</strong>), and the <strong>client app</strong>.</p>
<p>The <strong>resource owner</strong> performs an action (e.g. clicks on a link or a button) <span style="color:#ff0000;">[1]</span> in the <strong>web browser</strong>, which causes a &#8220;GET protected resource&#8221; request to be created. The <strong>web browser</strong> sends the request to the <strong>client app</strong> <span style="color:#ff0000;">[2]</span>.</p>
<blockquote><p>Note: The <strong>web browser</strong> does NOT typically have/show the protected resource URIs from the <strong>resource server</strong>. The <strong>client app</strong> typically publishes (HTML) links that are in its domain, and maintains the mapping/lookup in its executable code.</p>
<p>In other words, you will typically NOT see this kind of link in the HTML markup of the <strong>web browser</strong>:</p>
<p>http://resourceserver.com/customer/3/</p>
<p>Instead, you will see this kind of link:</p>
<p>http://clientapp.com/customer/3</p></blockquote>
<p>.</p>
<p>The <strong>client app</strong> asks &#8220;does this session have a valid <em>access token</em>?&#8221;</p>
<p>The answer will be &#8220;no&#8221;, because this is the first request for a protected resource.</p>
<p>Next, the <strong>client app</strong> asks &#8220;does the request from the <strong>web browser</strong> have a valid <em>authorization grant</em>?&#8221;</p>
<p>Again, the answer will be &#8220;no&#8221; (because this is the first request for a protected resource).</p>
<p>Consequently, the following sequence will be initiated, which will result in the acquisition of a valid <em>access token</em>:</p>
<ol>
<li>The <strong>resource owner</strong> authenticates with the <strong>authorization server</strong></li>
<li>The <strong>authorization server</strong> delivers an <em>authorization grant</em> to the <strong>client app</strong></li>
<li>The <strong>client app</strong> requests that the <strong>authorization server</strong> exchange the <em>authorization grant</em> for an <em>access token</em></li>
</ol>
<p>.</p>
<p>Before continuing, the essence of the original &#8220;GET protected resource&#8221; request must be retained. The sequence (below) will include three (3) HTTP 302 redirects, and we will be unable to persist the original request in a query string parameter.</p>
<p>There are several state persistence schemes available to us. For example, the <strong>client app</strong> can save this information in session state. Or, it can be sent (in the following response) as a <strong>web browser</strong> cookie. Whatever scheme you select as the programmer, you just need to retrieve the value later, when you need it.</p>
<p>.</p>
<p><span style="text-decoration:underline;">Sequence step 1: The <strong>resource owner</strong> authenticates with the <strong>authorization server</strong></span></p>
<p>The <strong>client app</strong> responds back <span style="color:#ff0000;">[3]</span> to the <strong>web browser</strong> with the following:</p>
<ol>
<li>a 302 redirect status code</li>
<li>a &#8220;location&#8221; header with the URI of the <strong>authorization server</strong>&#8216;s authentication UI, and the following query string key-value pairs&#8230;</li>
<ul>
<li>response_type=code &#8211; for a typical interaction</li>
<li>client_id= the <em>client app identifier</em></li>
<li>redirect_uri= a previously-established (between the <strong>client app</strong> and the <strong>authorization server</strong>) &#8220;redirection endpoint&#8221;</li>
</ul>
</ol>
<p>.</p>
<p>The <strong>web browser</strong> creates a new request, <span style="color:#ff0000;">[4]</span> &#8220;GET authentication UI&#8221;, and sends it to the (above) URI of the <strong>authorization server</strong>&#8216;s authentication UI.</p>
<blockquote><p>Note: The <strong>authorization server</strong>&#8216;s authentication UI may be a specially-created page/interface, solely for the use of <strong>resource owner</strong>s who want to authorize a client app. Alternatively, it may be the page/interface that is used by other general interactive users of the <strong>resource server</strong>.</p></blockquote>
<p>.</p>
<p>The <strong>authorization server</strong> validates the request (to ensure that all required key-value pairs are present), and responds with the authentication UI <span style="color:#ff0000;">[5]</span>, which will typically be an HTML form. (The key-value pairs are retained, in the URI query string, or in the <strong>authorization server</strong>&#8216;s state management and persistence system.)</p>
<p>.</p>
<p>The <strong>resource owner</strong> views the form <span style="color:#ff0000;">[6]</span>, enters their credentials <span style="color:#ff0000;">[7]</span>, and submits them (typically with a button click). The <strong>web browser</strong> creates a <span style="color:#ff0000;">[8]</span> &#8220;POST <em>resource owner credentials</em>&#8221; request, and sends the request to the <strong>authorization server</strong>.</p>
<p>After successfully authenticating, the <strong>authorization server</strong> responds back <span style="color:#ff0000;">[9]</span> to the <strong>web browser</strong> with the following:</p>
<ol>
<li>a 302 redirect status code</li>
<li>a &#8220;location&#8221; header with the URI of the <strong>client app</strong>&#8216;s redirection endpoint, and the following query string key-value pair&#8230;</li>
<ul>
<li>code= the <em>authorization grant</em> (known as the authorization code) that was generated by the <strong>authorization server</strong></li>
</ul>
</ol>
<p>.</p>
<p><span style="text-decoration:underline;">Sequence step 2: The <strong>authorization server</strong> delivers an <em>authorization grant</em> to the <strong>client app</strong></span></p>
<p>The <strong>web browser</strong> now has a valid authorization grant.</p>
<p>Using the URI from the response&#8217;s &#8220;location&#8221; header, the <strong>web browser</strong> creates a new request, <span style="color:#ff0000;">[10]</span> &#8220;GET authorization grant exchanged&#8221;, and sends it to the <strong>client app</strong>.</p>
<p>The <strong>client app</strong> inspects the request, which was received on the redirection endpoint, and asks &#8220;does the request from the <strong>web browser</strong> have a valid <em>authorization grant</em>?&#8221;</p>
<p>The answer will be &#8220;yes&#8221; (because a valid <em>authorization grant</em> was received on the redirection endpoint).</p>
<p>Before responding to the <strong>web browser</strong>, the <strong>client app</strong> continues with the following.</p>
<p>.</p>
<p><span style="text-decoration:underline;">Sequence step 3: The <strong>client app</strong> requests that the <strong>authorization server</strong> exchange the <em>authorization grant</em> for an <em>access token</em></span></p>
<p>A valid <em>authorization grant</em> can be exchanged for an <em>access token</em>. Therefore, the <strong>client app</strong> will create a new request, <span style="color:#ff0000;">[11]</span> &#8220;POST request <em>access token</em>&#8220;, and send it to the &#8220;token endpoint&#8221; on the <strong>authorization server</strong>. The request includes:</p>
<ol>
<li>an &#8220;authorization&#8221; header, which includes the <em>client app credentials</em></li>
<li>HTML form-encoded key-value pairs for the following parameters&#8230;</li>
<ul>
<li>grant_type=authorization_code</li>
<li>code= the <em>authorization grant</em> (known as the authorization code) that was generated by the <strong>authorization server</strong></li>
<li>redirect_uri=the previously-established (between the <strong>client app</strong> and the <strong>authorization server</strong>) redirection endpoint</li>
</ul>
</ol>
<p>.</p>
<p>The <strong>authorization server</strong> will inspect the request. It validates the <em>client app credentials</em> (with a lookup to the authorization store). It validates the <em>authorization grant</em> (with a lookup to the authorization store). If successful, it responds with an <em>access token</em> <span style="color:#ff0000;">[12]</span>.</p>
<p>The <em>access token</em> consists of a number of parameters, serialized as a JSON object, in the message body of an HTTP 200 response. The parameters include:</p>
<ul>
<li>access_token &#8211; string &#8211; the actual access token</li>
<li>token_type &#8211; string &#8211; for example, &#8220;bearer&#8221;</li>
<li>expires_in &#8211; integer, optional &#8211; the lifetime, in seconds, of the access token</li>
</ul>
<p>.</p>
<p>Now that the <strong>client app</strong> has a valid <em>access token</em>, it typically persists it in session state.</p>
<p>The <strong>client app</strong> is now ready to respond to the &#8220;GET authorization grant exchanged&#8221; request from the <strong>web browser</strong> (in sequence step 2 above).</p>
<p>The <strong>client app</strong> creates a response <span style="color:#ff0000;">[13]</span> that includes the following information, and sends it to the <strong>web browser</strong>:</p>
<ol>
<li>a 302 redirect status code</li>
<li>a &#8220;location&#8221; header with the URI of the original &#8220;GET protected resource&#8221; request (which may be retrieved from a <strong>web browser</strong> cookie, or the <strong>client app</strong>&#8216;s session state)</li>
</ol>
<p>.</p>
<p>Upon receipt, the <strong>web browser</strong> creates a <span style="color:#ff0000;">[14]</span> &#8220;GET protected resource&#8221; request, and sends it to the <strong>client app</strong>.</p>
<p>As above (when we started this journey), the <strong>client app</strong> asks &#8220;does this session have a valid <em>access token</em>?&#8221;</p>
<p>This time, the answer will be &#8220;yes&#8221;.</p>
<p>The <strong>client app</strong> creates a <span style="color:#ff0000;">[15]</span> &#8220;GET protected resource (with access token)&#8221; request, and sends it to the <strong>resource server</strong>. It includes:</p>
<ol>
<li>a request URI for the actual resource</li>
<li>an &#8220;authorization&#8221; header that includes 1) the token_type, and 2) the access_token values</li>
</ol>
<p>.</p>
<p>After validating the <em>access token</em>, the <strong>resource server</strong> responds back to the <strong>client app</strong> with the requested resource <span style="color:#ff0000;">[16]</span>.</p>
<p>The <strong>client app</strong> now has the protected resource that was originally requested. The protected resource is rendered for the <strong>web browser</strong> <span style="color:#ff0000;">[17]</span>, where it can be viewed <span style="color:#ff0000;">[18]</span> by the <strong>resource owner</strong>.</p>
<p>.</p>
<h4>Scenario &#8211; subsequent requests for protected resources</h4>
<p>This scenario covers the use case where a <strong>client app</strong>, which has a valid <em>access token</em>, requests a protected resource.</p>
<p>This scenario is documented on a sequence diagram, shown below. Each signal is identified with a number in square brackets, [#], and you will find them in the text that follows. The numbers used for the signals are the same as you saw in the first sequence diagram (but signals 3 through 14 inclusive aren&#8217;t there, because this scenario&#8217;s <strong>client app</strong> has a valid <em>access token</em>).</p>
<p><a href="http://petermcintyre.files.wordpress.com/2011/10/sequence-diagram-for-subsequent-requests1.png"><img class="alignnone size-full wp-image-4123" title="Sequence diagram for subsequent requests" src="http://petermcintyre.files.wordpress.com/2011/10/sequence-diagram-for-subsequent-requests1.png?w=600&#038;h=217" alt="" width="600" height="217" /></a></p>
<p>.</p>
<p>The <strong>resource owner</strong> performs an action (e.g. clicks on a link or a button) <span style="color:#ff0000;">[1]</span> in the <strong>web browser</strong>, which causes a &#8220;GET protected resource&#8221; request to be created. The <strong>web browser</strong> sends the request to the <strong>client app</strong> <span style="color:#ff0000;">[2]</span>.</p>
<p>As above, the <strong>client app</strong> asks &#8220;does this session have a valid <em>access token</em>?&#8221;</p>
<p>As you would expect, the answer will be &#8220;yes&#8221;.</p>
<p>The <strong>client app</strong> creates a <span style="color:#ff0000;">[15]</span> &#8220;GET protected resource (with access token)&#8221; request, and sends it to the <strong>resource server</strong>. It includes:</p>
<ol>
<li>a request URI for the actual resource</li>
<li>an &#8220;authorization&#8221; header that includes 1) the token_type, and 2) the access_token values</li>
</ol>
<p>.</p>
<p>After validating the <em>access token</em>, the <strong>resource server</strong> responds back to the <strong>client app</strong> with the requested resource <span style="color:#ff0000;">[16]</span>.</p>
<p>The <strong>client app</strong> now has the protected resource that was originally requested. The protected resource is rendered <span style="color:#ff0000;">[17]</span> for the <strong>web browser</strong>, where it can be viewed by the <strong>resource owner</strong> <span style="color:#ff0000;">[18]</span>.</p>
<p>.</p>
<hr noshade="noshade" size="11" />
<p>.</p>
<p>.</p>
<p>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/petermcintyre.wordpress.com/4096/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/petermcintyre.wordpress.com/4096/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/petermcintyre.wordpress.com/4096/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/petermcintyre.wordpress.com/4096/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/petermcintyre.wordpress.com/4096/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/petermcintyre.wordpress.com/4096/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/petermcintyre.wordpress.com/4096/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/petermcintyre.wordpress.com/4096/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/petermcintyre.wordpress.com/4096/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/petermcintyre.wordpress.com/4096/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/petermcintyre.wordpress.com/4096/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/petermcintyre.wordpress.com/4096/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/petermcintyre.wordpress.com/4096/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/petermcintyre.wordpress.com/4096/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=4096&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://petermcintyre.com/2011/10/30/web-svc-security-principles-oauth/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d94ddb24521352b6287292b05c01323?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">petermcintyre</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2011/10/web-service-as-a-resource-server.png" medium="image">
			<media:title type="html">Web service as a resource server</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2011/10/sequence-diagram-for-first-request3.png" medium="image">
			<media:title type="html">Sequence diagram for first request</media:title>
		</media:content>

		<media:content url="http://petermcintyre.files.wordpress.com/2011/10/sequence-diagram-for-subsequent-requests1.png" medium="image">
			<media:title type="html">Sequence diagram for subsequent requests</media:title>
		</media:content>
	</item>
		<item>
		<title>Handle hypermedia in a WCF Web API service</title>
		<link>http://petermcintyre.com/2011/10/11/wcf-web-api-hypermedia-intro/</link>
		<comments>http://petermcintyre.com/2011/10/11/wcf-web-api-hypermedia-intro/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 12:16:04 +0000</pubDate>
		<dc:creator>petermcintyre</dc:creator>
				<category><![CDATA[2011 Fall DPS907]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://petermcintyre.com/?p=3932</guid>
		<description><![CDATA[You have worked with XML and JSON in WCF Web API services. This post will introduce you to the handling of hypermedia. . This post was most recently updated in October 2011. . XML and JSON are WCF Web API defaults The WCF Web API services that you have created in the past work with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=3932&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>You have worked with XML and JSON in WCF Web API services. This post will introduce you to the handling of <a href="http://en.wikipedia.org/wiki/Hypermedia" target="_blank">hypermedia</a>.</p>
<p><span id="more-3932"></span></p>
<p>.</p>
<p>This post was most recently updated in October 2011.</p>
<p>.</p>
<h4>XML and JSON are WCF Web API defaults</h4>
<p>The WCF Web API services that you have created in the past work with XML and JSON data payloads. This capability is built in to the WCF Web API stack.</p>
<p>As a requestor, you indicate your desired data format:</p>
<ul>
<li>The &#8220;accept&#8221; header tells the service about the data format that you will accept, so the server will deliver the data in that format (e.g. &#8220;application/json&#8221;)</li>
<li>The &#8220;content-type&#8221; header tells the service about the data format that you are sending in the request body with a POST or PUT request</li>
</ul>
<p>.</p>
<p>When you write a web service method, it will have a return type, and some methods will accept arguments. The WCF Web API stack handles XML and JSON data formats by default.</p>
<p>The return type can be a data model object type, or a collection of them. Alternatively, a return type can be an HttpResponseMessage&lt;T&gt;, where T is a data model object type; this return type enables you to set other properties of the response message.</p>
<p>In either situation, the WCF Web API serializer takes care of serializing the data to the desired format.</p>
<p>For POST and PUT operations, where an object (or part of an object) is being sent to the method, the argument is a data model object type. A PUT handler will also include an argument which identifies the specific object to be updated. In addition, you can add an HttpRequestMessage argument, so that you can get access to properties of the request message.</p>
<p>In this situation, the WCF Web API serializer takes care of de-serializing the data sent with the request.</p>
<p>.</p>
<h4>Delivering hypermedia</h4>
<p>Delivering hypermedia &#8211; an image, a recording &#8211; is an uncomplicated task.</p>
<p>There are (at least) two ways to do this:</p>
<ol>
<li>Use an HttpResponseMessage object</li>
<li>Use a MediaTypeFormatter</li>
</ol>
<p>.</p>
<p><strong>In this post, we will use an HttpResponseMessage object.</strong> (In a later post, we may cover the other way, using a MediaTypeFormatter.)</p>
<p>Assume that we have this scenario: We have a web service method, which handles GET. The method takes an argument, which is an identifier for a &#8220;photo&#8221; that will be delivered. The photo is (obviously) stored digitally, as a property of an entity. In addition, the photo&#8217;s MIME type is stored as a property of the entity.</p>
<p>Yes, the WCF Web API is still &#8220;new&#8221; in October 2011. Finding documentation and examples is a small challenge for an unreleased preview technology. However, we will persevere.</p>
<p>The return type of the method should (must) be HttpResponseMessage. It has two properties which must be set:</p>
<ul>
<li>Content</li>
<li>Content.Headers.ContentType</li>
</ul>
<p>.</p>
<p>The online help for the <strong>Content property</strong> tells us that it &#8220;Represents the content of a message. This corresponds to the entity body defined in RFC 2616.&#8221;</p>
<p>Its data type is System.Net.Http.Content, which is an abstract class. One of its concrete implementations is System.Net.Http.ByteArrayContent. When you examine this class&#8217; documentation, you see that it has a constructor that uses a byte array. This matches the photo data that we have, so we can use it.</p>
<p>The online help for the <strong>Content.Headers.ContentType property</strong> is intended to hold the response&#8217;s &#8220;content-type&#8221; header value.</p>
<p>Its data type is System.Net.Http.Headers.MediaTypeHeaderValue. When you examine this class&#8217; documentation, you see that it has a constructor that uses a string. This matches the photo MIME type that we have, so we can use it.</p>
<p>In summary, the method body has two lines of code that prepare the response. See the code sample below. Assume that the &#8220;photo&#8221; object is an typical model object, which has properties for storing hypermedia content and its MIME type.</p>
<p><pre class="brush: csharp;">
    // Create a response object
    HttpResponseMessage response = new HttpResponseMessage();

    // Configure it with the photo content and the MIME type
    response.Content = new ByteArrayContent(photo.Content);
    response.Content.Headers.ContentType =
        new System.Net.Http.Headers.MediaTypeHeaderValue(photo.MIMEType);

    return response;
</pre></p>
<p>.</p>
<h4>Accepting hypermedia</h4>
<p>This course&#8217;s <a title="DPS907 WSA500 Lab 3 (due Thu Oct 20)" href="http://petermcintyre.com/dps907/graded-work/lab3/">Lab 3</a> covers the task of accepting a photo in a WCF Web API service. It walks you through the coding tasks to re-purpose the Employees entity of the Northwind data store (or, in your copy, nwEmployees), so that you can store a modern format photo in the &#8220;Photo&#8221; property.</p>
<p>In general, when designing a web service method to accept hypermedia, you can obviously configure it for POST or PUT operations. The method body implementation will be almost the same (POST to a collection URI, and PUT to a specific object URI).</p>
<p>The method signature must include an HttpRequestMessage argument, so that you can get access to the request message headers and body. From the headers, you must extract the hypermedia&#8217;s MIME type. From the body, you must (obviously) extract the hypermedia.</p>
<p>In summary, the method body has two lines of code that accept the request data. See the code sample below. As above, assume that the &#8220;photo&#8221; object is a typical model object, which has properties for storing hypermedia content and its MIME type.</p>
<p><pre class="brush: csharp;">
    // First, the hypermedia content...
    photo.Content = request.Content.ReadAsByteArray();
    // Next, the MIME type...
    photo.MIMEType = request.Content.Headers.ContentType.ToString();
</pre></p>
<p>.</p>
<h4>Design considerations</h4>
<p>When handling hypermedia, the way you design your methods is important.</p>
<p>Consider this scenario: You have an entity that describes a real-world object. It has many descriptive properties. It also has a hypermedia property (e.g. a photo).</p>
<p>When you GET a specific object, what do you expect to deliver/receive? Probably, a fully-serialized object, with the hypermedia data as part of the delivery package. This happens because the request&#8217;s default &#8220;accept&#8221; header will tell the service to serialize the object to XML or JSON.</p>
<p>What if you want the hypermedia only, in its native format (e.g. image/png)?</p>
<p>Should you create another method, which has another URI template (e.g. employee/{id}/photo)?</p>
<p>Or, should you enable the requestor to specify their desired data format in an accept header (e.g. accept: image/*), and process the request accordingly?</p>
<p>What about this slightly different scenario: You have an entity specifically for hypermedia (digital content). As such, it really is a container for hypermedia items. Typically, it is associated with other business entities.</p>
<p>How does this change your approach, given that a request for a specific hypermedia item fulfills the intent of the requestor?</p>
<p>The bottom line of all this is that you must consider your situation, and design and code accordingly. There&#8217;s no &#8220;one true way&#8221;, although some approaches are better than others.</p>
<p>.</p>
<hr noshade="noshade" size="11" />
<p>.</p>
<p>.</p>
<p>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/petermcintyre.wordpress.com/3932/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/petermcintyre.wordpress.com/3932/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/petermcintyre.wordpress.com/3932/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/petermcintyre.wordpress.com/3932/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/petermcintyre.wordpress.com/3932/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/petermcintyre.wordpress.com/3932/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/petermcintyre.wordpress.com/3932/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/petermcintyre.wordpress.com/3932/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/petermcintyre.wordpress.com/3932/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/petermcintyre.wordpress.com/3932/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/petermcintyre.wordpress.com/3932/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/petermcintyre.wordpress.com/3932/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/petermcintyre.wordpress.com/3932/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/petermcintyre.wordpress.com/3932/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=3932&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://petermcintyre.com/2011/10/11/wcf-web-api-hypermedia-intro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d94ddb24521352b6287292b05c01323?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">petermcintyre</media:title>
		</media:content>
	</item>
		<item>
		<title>WCF Web API service, with EF data model, supporting POST, PUT, DELETE (on an ASP.NET web site)</title>
		<link>http://petermcintyre.com/2011/10/03/wcf-web-api-svc-ef-post-put-delete/</link>
		<comments>http://petermcintyre.com/2011/10/03/wcf-web-api-svc-ef-post-put-delete/#comments</comments>
		<pubDate>Mon, 03 Oct 2011 21:18:35 +0000</pubDate>
		<dc:creator>petermcintyre</dc:creator>
				<category><![CDATA[2011 Fall DPS907]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://petermcintyre.wordpress.com/?p=3826</guid>
		<description><![CDATA[This post builds upon the topics in WCF Web API service with an Entity Framework data model. We add the ability to support POST, PUT, and DELETE operations. . This post was most recently updated in October 2011. It is the third post in a multipart series on WCF Web API, and is intended to be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=3826&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post builds upon the topics in <a title="WCF Web API service with an Entity Framework data model (on an ASP.NET web site)" href="http://petermcintyre.wordpress.com/2011/10/03/wcf-web-api-svc-with-ef-data-model/">WCF Web API service with an Entity Framework data model</a>. We add the ability to support POST, PUT, and DELETE operations.</p>
<p><span id="more-3826"></span></p>
<p>.</p>
<p>This post was most recently updated in October 2011.</p>
<p>It is the third post in a multipart series on WCF Web API, and is intended to be used by students in Seneca&#8217;s diploma- and degree-level software development programs, and any other entry- to mid-level developer.</p>
<p>.</p>
<h4>This post was inspired by&#8230;</h4>
<p>The WCF Web API programming team discuss POST, PUT, and DELETE support in this note:</p>
<p><a href="http://wcf.codeplex.com/wikipage?title=Getting%20started%3a%20Adding%20support%20for%20getting%20a%20single%20resource%20and%20supporting%20POST%2c%20PUT%20and%20DELETE%20methods" target="_blank">Adding support for&#8230; POST, PUT, and DELETE methods</a></p>
<p>We complement the coverage, by building on the first to posts in this series:</p>
<p><a title="Getting started with WCF Web API (on an ASP.NET web site)" href="http://petermcintyre.wordpress.com/2011/09/23/wcf-web-api-on-asp-net/" target="_blank">Getting started with a WCF Web API service</a></p>
<p><a title="WCF Web API service with an Entity Framework data model (on an ASP.NET web site)" href="http://petermcintyre.wordpress.com/2011/10/03/wcf-web-api-svc-with-ef-data-model/" target="_blank">WCF Web API service with an Entity Framework data model</a></p>
<p>.</p>
<p>Make sure that you use your HTTP Test Client to prove that your service works correctly.</p>
<p>.</p>
<h4>POST methods</h4>
<p>The most important idea is that you must POST to a collection URI. Other features of a POST method:</p>
<ul>
<li>A WebInvoke attribute is used; the URI template should be the same as the one used to GET the collection, but its method must be &#8220;POST&#8221;</li>
<li>It includes an argument for the new object to be added to the collection</li>
<li>Its return type should be HttpResponseMessage&lt;T&gt;, so that we can set the status code</li>
<li>The code adds the object to the context, and then saves changes</li>
</ul>
<p>.</p>
<p>A sample method follows.</p>
<p><pre class="brush: csharp;">
[WebInvoke(UriTemplate = &quot;regions&quot;, Method = &quot;POST&quot;)]
public HttpResponseMessage&lt;nwRegion&gt; AddRegion(nwRegion region)
{
    // FYI - you must supply a RegionID, because its key is NOT auto-incrementing

    // Add the region that was passed in as the argument
    context.nwRegions.Add(region);
    context.SaveChanges();

    // Prepare the response - we want to return &quot;201 Created&quot;
    HttpResponseMessage&lt;nwRegion&gt; response = new HttpResponseMessage&lt;nwRegion&gt;(region, HttpStatusCode.Created);
    return response;
}
</pre></p>
<p>.</p>
<h4>PUT methods</h4>
<p>The most important idea is that you must PUT to a URI for a specific object. Other features of a PUT method:</p>
<ul>
<li>A WebInvoke attribute is used; the URI template should be the same as the one used to GET a specific object, but its method must be &#8220;PUT&#8221;</li>
<li>It includes an argument for the updated object, and the object key/ID</li>
<li>Its return type should be the object&#8217;s type</li>
<li>The code fetches the object to the context, and then saves changes/udpates</li>
</ul>
<p>.</p>
<p>A sample method follows.</p>
<p><pre class="brush: csharp;">
[WebInvoke(UriTemplate = &quot;region/{id}&quot;, Method = &quot;PUT&quot;)]
public nwRegion RegionUpdate(nwRegion region, string id)
{
    // Local variables
    int _id;
    nwRegion _object;

    // If the argument is not an integer, return an error
    if (!Int32.TryParse(id, out _id)) throw new HttpResponseException(HttpStatusCode.NotFound);

    // Attempt to locate the object
    _object = context.nwRegions.Find(_id);

    // If the object is null, return an error
    if (_object == null) throw new HttpResponseException(HttpStatusCode.NotFound);

    // Update the changed values
    context.Entry(_object).CurrentValues.SetValues(region);
    context.SaveChanges();

    return _object;
}
</pre></p>
<p>.</p>
<h4>DELETE methods</h4>
<p>The most important idea is that you must DELETE to a URI for a specific object. Other features of a DELETE method:</p>
<ul>
<li>A WebInvoke attribute is used; the URI template should be the same as the one used to GET a specific object, but its method must be &#8220;DELETE&#8221;</li>
<li>It includes an argument for the object key/ID</li>
<li>Its return type should be the object&#8217;s type (or HttpResponseMessage, with an empty Content property, and an HttpStatusCode of OK)</li>
<li>The code fetches the object to the context, and then deletes it</li>
</ul>
<p>.</p>
<p>A sample method follows.</p>
<p><pre class="brush: csharp;">
[WebInvoke(UriTemplate = &quot;region/{id}&quot;, Method = &quot;DELETE&quot;)]
public nwRegion RegionDelete(string id)
{
    // Local variables
    int _id;
    nwRegion _object;

    // If the argument is not an integer, return an error
    if (!Int32.TryParse(id, out _id)) throw new HttpResponseException(HttpStatusCode.NotFound);

    // Attempt to locate the object
    _object = context.nwRegions.Find(_id);

    // If the object is null, return an error
    if (_object == null) throw new HttpResponseException(HttpStatusCode.NotFound);

    // Delete the object
    context.nwRegions.Remove(_object);
    context.SaveChanges();

    return _object;
}
</pre></p>
<p>.</p>
<h4>On your own</h4>
<p>In your web service, add methods that enable you to support POST, PUT, and DELETE. You will also get practice by doing Lab 2.</p>
<p>.</p>
<hr noshade="noshade" size="11" />
<p>.</p>
<p>.</p>
<p>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/petermcintyre.wordpress.com/3826/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/petermcintyre.wordpress.com/3826/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/petermcintyre.wordpress.com/3826/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/petermcintyre.wordpress.com/3826/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/petermcintyre.wordpress.com/3826/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/petermcintyre.wordpress.com/3826/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/petermcintyre.wordpress.com/3826/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/petermcintyre.wordpress.com/3826/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/petermcintyre.wordpress.com/3826/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/petermcintyre.wordpress.com/3826/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/petermcintyre.wordpress.com/3826/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/petermcintyre.wordpress.com/3826/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/petermcintyre.wordpress.com/3826/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/petermcintyre.wordpress.com/3826/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=petermcintyre.com&amp;blog=2985491&amp;post=3826&amp;subd=petermcintyre&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://petermcintyre.com/2011/10/03/wcf-web-api-svc-ef-post-put-delete/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d94ddb24521352b6287292b05c01323?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">petermcintyre</media:title>
		</media:content>
	</item>
	</channel>
</rss>
