<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>WCF</title>
        <link>http://geekswithblogs.net/vitus/category/10367.aspx</link>
        <description>WCF</description>
        <language>ru-RU</language>
        <copyright>Vitus</copyright>
        <managingEditor>vitus@movaxbx.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Client part of WCF REST Starter Kit</title>
            <link>http://geekswithblogs.net/vitus/archive/2009/10/28/client-part-of-wcf-rest-starter-kit.aspx</link>
            <description>&lt;p&gt;WCF REST Starter Kit Preview 2 contains not only tools for creating REST services. It include rich set of client tools, that allow to do HTTP-requests and process service response in more convenient way. I create small overview of it basic features.&lt;/p&gt;
&lt;p&gt;We’ll create a simple WPF desktop client for Yahoo Shopping Web Services. Our client sill search products by the keyword. Details of Search API is available here, but information about GET-request format and service URI is enough. For example, if we want to search for “digital camera”, we shall use following URL: &lt;a href="http://shopping.yahooapis.com/ShoppingService/v3/productSearch?appid=YahooDemo&amp;amp;query=digital+camera&amp;amp;show_numratings=1"&gt;http://shopping.yahooapis.com/ShoppingService/v3/productSearch?appid=YahooDemo&amp;amp;query=digital+camera&amp;amp;show_numratings=1&lt;/a&gt;. Parameter &lt;strong&gt;appId &lt;/strong&gt;is a Yahoo id of your app. We can you demo id for our purposes and use “YahooDemo”. Keyword is passed through &lt;strong&gt;query &lt;/strong&gt;parameter, and &lt;strong&gt;show_numratings&lt;/strong&gt;=1 allow us to receive user rating of each product in the results. So, we need to do some GET-request and process server response.&lt;/p&gt;
&lt;p&gt;User of our application enter search keywords to the TextBox, and we use Microsoft.Http.HttpQueryString class for making the URL:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; keyword = searchString.Text.ToLower().Trim().Replace(&lt;span style="color: rgb(0, 96, 128);"&gt;' '&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;'+'&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;HttpQueryString query = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpQueryString();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;query.Add(&lt;span style="color: rgb(0, 96, 128);"&gt;"appid"&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;"YahooDemo"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;query.Add(&lt;span style="color: rgb(0, 96, 128);"&gt;"query"&lt;/span&gt;, keyword);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;query.Add(&lt;span style="color: rgb(0, 96, 128);"&gt;"show_numratings"&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;"1"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;We simply add “parameter-value” pairs to the list, and call of MakeQueryString() method allow us to get the Uri:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; uri = query.MakeQueryString(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Uri(&lt;span style="color: rgb(0, 96, 128);"&gt;"http://localhost/script.php"&lt;/span&gt;)).AbsoluteUri;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;In this example we receive following: &lt;em&gt;http://localhost/script.php?appid=YahooDemo&amp;amp;query=notebook&amp;amp;show_numratings=1&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;We’ll use HttpClient class for sending request to the server. It allow us to execute wide range of HTTP-requests, it have multiple settings, for example HTTP headers, timeout of sending/receiving and other, it support sync and async requests, etc. And I think, it has more convenient API, then classic HttpWebRequest. And WebClient class don’t have some “must have” features, such as timeout settings (for example, if you try to POST large amount of data to the server through the poor channel, you often fail with timeout). Let’s take a look at HttpClient class:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;HttpClient client = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpClient(&lt;span style="color: rgb(0, 96, 128);"&gt;@"http://shopping.yahooapis.com/ShoppingService/V3/"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;client.DefaultHeaders.UserAgent.AddString(&lt;span style="color: rgb(0, 96, 128);"&gt;@"Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 4.0.20506)"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;HttpResponseMessage response = client.Get(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Uri(&lt;span style="color: rgb(0, 96, 128);"&gt;"productSearch"&lt;/span&gt;, UriKind.Relative), query);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;With these 3 lines of code we perform sync GET-request to the server, and receive the response. We create instance of HttpClient with the base part of URL in the constructor. Then we add UserAgent header, because else server is not process the request normally. After that we make a request by calling Get() extension method. We can call REST service in other way:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;HttpResponseMessage response = client.Send(HttpMethod.GET,query.MakeQueryString(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Uri(&lt;span style="color: rgb(0, 96, 128);"&gt;"productSearch"&lt;/span&gt;, UriKind.Relative)), HttpContent.CreateEmpty());&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Here is used “universal” Send() method, where type of HTTP-method is typed explicitly. Of course, Get(), Post() and etc. is calling Send() internally, but usage of them is making code more “human-readable”. You can check state of response:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;response.EnsureStatusIsSuccessful();&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;So, if HTTP-response code is not 2xx, then we get an exception. The value of response code is available through StatusCode property.&lt;/p&gt;
&lt;p&gt;Ok, we get an XML response. But we need more not an XML but a collection of entities. You can create entity classes manually. Or you can route this task to the “Paste XML as Type” add-in for VS 2008. This add-in is included in the WCF REST Starter Kit. It have very simple UI – just a single item in the Edit menu of VS:&lt;/p&gt;
&lt;p&gt;&lt;img height="250" border="0" width="269" src="http://geekswithblogs.net/images/geekswithblogs_net/vitus/WindowsLiveWriter/ClientpartofWCFRESTStarterKit_908C/image8_3.png" alt="image8" title="image8" style="border: 0px none ; display: block; float: none; margin-left: auto; margin-right: auto;" /&gt;&lt;/p&gt;
&lt;p&gt;You can copy XML response of the server and use this add-in. As a result you’ll get a set of generated entity classes, using it you can parse server response and get an instances. One disadvantage – sometime names of the types and properties is not useful and you need to change it manually.&lt;/p&gt;
&lt;p&gt;So, you can get collection of the elements as following:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;ProductSearch results = response.Content.ReadAsXmlSerializable&amp;lt;ProductSearch&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;That’s all. We only need to data-bind result of request and or client is ready:&lt;/p&gt;
&lt;p&gt;&lt;img height="328" border="0" width="379" src="http://geekswithblogs.net/images/geekswithblogs_net/vitus/WindowsLiveWriter/ClientpartofWCFRESTStarterKit_908C/image16_3.png" alt="image16" title="image16" style="border: 0px none ; display: block; float: none; margin-left: auto; margin-right: auto;" /&gt;&lt;/p&gt;
&lt;p&gt;We can receive server response in other ways:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;as &lt;strong&gt;byte[]&lt;/strong&gt; by calling ReadAsByteArray(); &lt;/li&gt;
    &lt;li&gt;as &lt;strong&gt;string&lt;/strong&gt; by calling ReadAsString(); &lt;/li&gt;
    &lt;li&gt;as &lt;strong&gt;stream&lt;/strong&gt; by calling ReadAsStream(); &lt;/li&gt;
    &lt;li&gt;as &lt;strong&gt;XElement&lt;/strong&gt; for processing with XLINQ by calling ReadAsXElement(); &lt;/li&gt;
    &lt;li&gt;as &lt;strong&gt;XmlReader&lt;/strong&gt; by calling ReadAsXmlReader(); &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Ok, but that about services, which use JSON or RSS/Atom format? Starter Kit’s client part have appropriate extension-methods for HttpContent: ReadAsJsonDataContract&amp;lt;T&amp;gt;() and ReadAsSyndicationFeed().&lt;/p&gt;
&lt;p&gt;With the source codes of WCF REST Starter Kit Preview 2 you can get an interesting WPF application, that allow to perform different types of HTTP-requests and analyze the response. You can see other “real world” examples of usage client parts on this sample app. And you must know, that I describe only basic features of client part of Starter Kit. It contains interesting and useful advanced possibilities.&lt;/p&gt; &lt;img src="http://geekswithblogs.net/vitus/aggbug/135773.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Vitus</dc:creator>
            <guid>http://geekswithblogs.net/vitus/archive/2009/10/28/client-part-of-wcf-rest-starter-kit.aspx</guid>
            <pubDate>Wed, 28 Oct 2009 08:05:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/vitus/comments/135773.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/vitus/archive/2009/10/28/client-part-of-wcf-rest-starter-kit.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/vitus/comments/commentRss/135773.aspx</wfw:commentRss>
        </item>
        <item>
            <title>WCF REST services: hosting in the IIS7</title>
            <link>http://geekswithblogs.net/vitus/archive/2009/07/12/wcf-rest-services-hosting-in-the-iis7.aspx</link>
            <description>&lt;p&gt;Not long ago I notice interesting “feature” of WCF REST, hosted in the IIS7: when size of data from client exceeds some value, service broke the connection.    &lt;br /&gt;
I created test service, where I could reproduce this issue, using WCF REST Starter Kit (you can download &lt;a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24644"&gt;here&lt;/a&gt; actual release, Preview 2). One of service's method is:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;[WebHelp(Comment = &lt;span style="color: rgb(0, 96, 128);"&gt;"Sample description for DoWork"&lt;/span&gt;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;[WebInvoke(UriTemplate = &lt;span style="color: rgb(0, 96, 128);"&gt;"DoWork"&lt;/span&gt;, Method = &lt;span style="color: rgb(0, 96, 128);"&gt;"POST"&lt;/span&gt;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;[OperationContract]&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; SampleResponseBody DoWork(SampleRequestBody request)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SampleResponseBody()&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;        Value = String.Format(&lt;span style="color: rgb(0, 96, 128);"&gt;"Data: {0}, Length: {1}"&lt;/span&gt;, request.Data, &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;                                request.Array.Length)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    };&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;So, this method has 1 parameter, which is passed by the POST method. Code of SampleRequestBody entity:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; SampleRequestBody&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; Data { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;byte&lt;/span&gt;[] Array { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;I set large quotas and 10 minutes request timeout in the binding configuration (in web.config file) for my test service:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;bindings&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;webHttpBinding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;binding&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="webBinding"&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;             &lt;span style="color: rgb(255, 0, 0);"&gt;maxBufferSize&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="152428800"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;maxReceivedMessageSize&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="152428800"&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;             &lt;span style="color: rgb(255, 0, 0);"&gt;receiveTimeout&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="00:10:00"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;      &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;readerQuotas&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;maxStringContentLength&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="152428800"&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;                    &lt;span style="color: rgb(255, 0, 0);"&gt;maxArrayLength&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="152428800"&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;                    &lt;span style="color: rgb(255, 0, 0);"&gt;maxBytesPerRead&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="4096"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;binding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;webHttpBinding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;bindings&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;After that I successfully host my test service in the local development server, and it work normal. Here screenshot of client console application. How you can see, service side received 30Mb file successfully.&lt;/p&gt;
&lt;p&gt;&lt;img height="67" border="0" width="564" src="http://geekswithblogs.net/images/geekswithblogs_net/vitus/WindowsLiveWriter/WCFRESTserviceshostingintheIIS7_14FAD/image_3.png" alt="image" title="image" style="border-width: 0px; display: inline;" /&gt; &lt;/p&gt;
&lt;p&gt;Then I host my test service in the IIS7. And when I try to call service method from the client, I get an exception:&lt;/p&gt;
&lt;p&gt;&lt;img height="123" border="0" width="567" src="http://geekswithblogs.net/images/geekswithblogs_net/vitus/WindowsLiveWriter/WCFRESTserviceshostingintheIIS7_14FAD/image_8.png" alt="image" title="image" style="border: 0px none ; display: inline;" /&gt;&lt;/p&gt;
&lt;p&gt;I check Windows EventLog, but it don’t contain any items about my service. Next step is to allow IIS7 accept large size requests. You can do that with &lt;a href="http://msdn.microsoft.com/en-us/library/e1f13641.aspx"&gt;maxRequestLength&lt;/a&gt; attribute:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;httpRuntime&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;maxRequestLength&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="xxx"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;where &lt;em&gt;xxx&lt;/em&gt; is maximum request size in KB.&lt;/p&gt;
&lt;p&gt;But after that service still can’t serve requests normally. And I noticed, that exception on client side was changed:&lt;/p&gt;
&lt;p&gt;&lt;img height="127" border="0" width="559" src="http://geekswithblogs.net/images/geekswithblogs_net/vitus/WindowsLiveWriter/WCFRESTserviceshostingintheIIS7_14FAD/image_9.png" alt="image" title="image" style="border: 0px none ; display: inline;" /&gt; &lt;/p&gt;
&lt;p&gt;I got 404 error on my client side. Windows EventLogs still don’t had any useful info, and I decided &lt;a href="http://msdn.microsoft.com/en-us/library/ms730064.aspx"&gt;enable logging&lt;/a&gt; of my service. When I try to call service, it log is empty. And I think, that requests from client is dropped by something before they achieve the service, i.e. by IIS7. I check IIS logs, and found, that IIS reply 404 error with subcode 13. It’s &lt;a href="http://support.microsoft.com/default.aspx/kb/943891"&gt;means&lt;/a&gt;, that incoming request is too large. I search &lt;a href="http://forums.iis.net/"&gt;forums.iis.net&lt;/a&gt;, and locate some interesting option. File %windir%\System32\inetsrv\config\applicationHost.config contain &amp;lt;requestFiltering&amp;gt; section. I add following parameter:&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;requestLimits&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;maxAllowedContentLength&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="xxx"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;where &lt;em&gt;xxx &lt;/em&gt;is max size of request. And when I set it, service work normal.&lt;/p&gt;
&lt;p&gt;One trick with applicationHost.config: in the x64 version of Windows this file is not visible from 32bit file managers such as FAR Manager and other. Windows Explorer show it normally. I think, that 32bit applications is redirected to some other place, that doesn’t contain applicationHost.config. For example, VS 2008 devenv.exe is 32bit app, and you can’t edit applicationHost.config file in Visual Studio. Use notepad for edit.&lt;/p&gt;
&lt;p&gt;So there are 3 steps to allow large size requests:&lt;/p&gt;
&lt;p&gt;1. deal with binding configuration: set &lt;em&gt;maxReceivedMessageSize&lt;/em&gt;, &lt;em&gt;maxBufferSize&lt;/em&gt; etc. parameters;&lt;/p&gt;
&lt;p&gt;2. set &lt;em&gt;maxRequestLength&lt;/em&gt; attribute of &lt;em&gt;&amp;lt;httpRuntime&amp;gt;&lt;/em&gt; in the web.config;&lt;/p&gt;
&lt;p&gt;3. set max request size in the &lt;em&gt;&amp;lt;requestFiltering&amp;gt;&lt;/em&gt; section and &lt;em&gt;&amp;lt;requestLimit&amp;gt;&lt;/em&gt; element in the  %windir%\System32\inetsrv\config\applicationHost.config;&lt;/p&gt; &lt;img src="http://geekswithblogs.net/vitus/aggbug/133437.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Vitus</dc:creator>
            <guid>http://geekswithblogs.net/vitus/archive/2009/07/12/wcf-rest-services-hosting-in-the-iis7.aspx</guid>
            <pubDate>Sun, 12 Jul 2009 08:14:05 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/vitus/comments/133437.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/vitus/archive/2009/07/12/wcf-rest-services-hosting-in-the-iis7.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/vitus/comments/commentRss/133437.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>
