<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Consuming REST/JSON services in Silverlight 4</title><link>http://blogs.msdn.com/b/carlosfigueira/archive/2010/04/29/consuming-rest-json-services-in-silverlight-4.aspx</link><description>In the previous post, which talked about the new Web programming model support for SL4, I mentioned that the support for strongly-typed consumption of REST/JSON services wasn't available out of the box. This post will show how to plug additional code</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Consuming REST/JSON services in Silverlight 4</title><link>http://blogs.msdn.com/b/carlosfigueira/archive/2010/04/29/consuming-rest-json-services-in-silverlight-4.aspx#10339180</link><pubDate>Mon, 13 Aug 2012 19:29:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10339180</guid><dc:creator>Bhavesh</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I have a question. I have SL 5 project (Client and Web application). Now I need to call third party API which can return response in JSON or XML. My question is about from where to call this third party API? - From Client application or Web application in the SL 5 project...? Can you please guide.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Bhavesh&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10339180" width="1" height="1"&gt;</description></item><item><title>re: Consuming REST/JSON services in Silverlight 4</title><link>http://blogs.msdn.com/b/carlosfigueira/archive/2010/04/29/consuming-rest-json-services-in-silverlight-4.aspx#10276012</link><pubDate>Thu, 01 Mar 2012 22:38:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10276012</guid><dc:creator>CarlosFigueira</dc:creator><description>&lt;p&gt;Paul, if you want to read the response headers (including the Location header), you&amp;#39;ll need to, prior to calling the EndXXX method, wrap the call in a new OperationContextScope. That way you&amp;#39;ll be able to access the HTTP response headers using the HttpResponseMessageProperty (via OperationContext.Current.IncomingMessageProperties). Notice that you need to select the WebRequestCreator.ClientHttp for the web request, otherwise you won&amp;#39;t have access to the response headers.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10276012" width="1" height="1"&gt;</description></item><item><title>re: Consuming REST/JSON services in Silverlight 4</title><link>http://blogs.msdn.com/b/carlosfigueira/archive/2010/04/29/consuming-rest-json-services-in-silverlight-4.aspx#10172447</link><pubDate>Wed, 08 Jun 2011 09:00:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10172447</guid><dc:creator>Rick</dc:creator><description>&lt;p&gt;Found out nice article describing PUT and DELETE&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://vordoom.com/post/2011/05/21/Consume-REST-services-in-Silverlight.aspx"&gt;vordoom.com/.../Consume-REST-services-in-Silverlight.aspx&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10172447" width="1" height="1"&gt;</description></item><item><title>re: Consuming REST/JSON services in Silverlight 4</title><link>http://blogs.msdn.com/b/carlosfigueira/archive/2010/04/29/consuming-rest-json-services-in-silverlight-4.aspx#10143264</link><pubDate>Fri, 18 Mar 2011 20:51:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10143264</guid><dc:creator>Paul Cavacas</dc:creator><description>&lt;p&gt;Any suggestion on how I can read back a Location Header from the response. &amp;nbsp;I have a JSON service that does a POST to Insert/Update data. &amp;nbsp;If it does an insert then the Http header is written back with the ID of the record that was inserted,i.e.&lt;/p&gt;
&lt;p&gt;I send a request like&lt;/p&gt;
&lt;p&gt;http://localhost.:39330/MyService.svc/SaveApproval/0 &lt;/p&gt;
&lt;p&gt;with a Post Body of &lt;/p&gt;
&lt;p&gt;{&amp;quot;ActionDate&amp;quot;:null,&amp;quot;Comments&amp;quot;:null,&amp;quot;DocumentId&amp;quot;:360,&amp;quot;Id&amp;quot;:0,&amp;quot;RoundId&amp;quot;:219,&amp;quot;Status&amp;quot;:null,&amp;quot;User&amp;quot;:{&amp;quot;BP&amp;quot;:null,&amp;quot;D&amp;quot;:null,&amp;quot;Dep&amp;quot;:null,&amp;quot;E&amp;quot;:null,&amp;quot;FN&amp;quot;:&amp;quot;Paul&amp;quot;,&amp;quot;LC&amp;quot;:null,&amp;quot;LN&amp;quot;:&amp;quot;smith&amp;quot;,&amp;quot;UN&amp;quot;:&amp;quot;somebody&amp;quot;}}&lt;/p&gt;
&lt;p&gt;then the reply comes back with the following headers&lt;/p&gt;
&lt;p&gt;HTTP/1.1 201 Created&lt;/p&gt;
&lt;p&gt;Server: ASP.NET Development Server/10.0.0.0&lt;/p&gt;
&lt;p&gt;Date: Fri, 18 Mar 2011 20:37:36 GMT&lt;/p&gt;
&lt;p&gt;X-AspNet-Version: 4.0.30319&lt;/p&gt;
&lt;p&gt;Location: http://localhost.:39330/LabelApprovalService.svc/SaveApproval/64&lt;/p&gt;
&lt;p&gt;Cache-Control: private&lt;/p&gt;
&lt;p&gt;Content-Length: 0&lt;/p&gt;
&lt;p&gt;Connection: Close&lt;/p&gt;
&lt;p&gt;Notice the 201 status and the Location Header which says the ID of the newly created record is 64.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10143264" width="1" height="1"&gt;</description></item><item><title>re: Consuming REST/JSON services in Silverlight 4</title><link>http://blogs.msdn.com/b/carlosfigueira/archive/2010/04/29/consuming-rest-json-services-in-silverlight-4.aspx#10106085</link><pubDate>Thu, 16 Dec 2010 17:49:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10106085</guid><dc:creator>CarlosFigueira</dc:creator><description>&lt;p&gt;There&amp;#39;s no out-of-the-box binding in SL which sends JSON data - which is one of the reasons for this post. Do you need the communication between WCF and SL to be in JSON? JSON is definitely more concise than XML, but in SL we also support the WCF binary encoding, which makes the messages quite small. You can create a custom binding using HTTP and Binary (which works on both WCF/Desktop and Silverlight):&lt;/p&gt;
&lt;p&gt;&amp;lt;customBinding&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;lt;binding name=&amp;quot;BinaryOverHttp&amp;quot;&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;binaryMessageEncoding/&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;httpTransport&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;lt;/binding&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;/customBinding&amp;gt;&lt;/p&gt;
&lt;p&gt;Or in code:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; CustomBinding binding = new CustomBinding(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;new BinaryMessageEncodingBindingElement(),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;new HttpTransportBindingElement());&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10106085" width="1" height="1"&gt;</description></item><item><title>re: Consuming REST/JSON services in Silverlight 4</title><link>http://blogs.msdn.com/b/carlosfigueira/archive/2010/04/29/consuming-rest-json-services-in-silverlight-4.aspx#10103996</link><pubDate>Mon, 13 Dec 2010 11:48:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10103996</guid><dc:creator>Theo</dc:creator><description>&lt;p&gt;Thanks Carlos for your reply, I was not able to find which binding in Silverlight i need to use that supports JSON out-of-the-box. May I am looking at a worng place, can please you guide me to the right place where I can get the details or let me know which biding I can use in Silverlight that sends data in JSON.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10103996" width="1" height="1"&gt;</description></item><item><title>re: Consuming REST/JSON services in Silverlight 4</title><link>http://blogs.msdn.com/b/carlosfigueira/archive/2010/04/29/consuming-rest-json-services-in-silverlight-4.aspx#10102938</link><pubDate>Fri, 10 Dec 2010 00:25:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10102938</guid><dc:creator>CarlosFigueira</dc:creator><description>&lt;p&gt;Theo, for &amp;quot;normal&amp;quot; WCF service you don&amp;#39;t need to use a special encoder - there&amp;#39;s already support in Silverlight for consuming such services, as long as the endpoint uses a binding which is supported by Silverlight, such as BasicHttpBinding. You can simply use the equivalent SL bindings which are shipped out-of-the-box.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10102938" width="1" height="1"&gt;</description></item><item><title>re: Consuming REST/JSON services in Silverlight 4</title><link>http://blogs.msdn.com/b/carlosfigueira/archive/2010/04/29/consuming-rest-json-services-in-silverlight-4.aspx#10102632</link><pubDate>Thu, 09 Dec 2010 13:52:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10102632</guid><dc:creator>Theo</dc:creator><description>&lt;p&gt;Hi Carlos,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Thanks for this wonderful post, can you let me know what change will i need to do if i want to use the same encoder with a normal WCF service instead of a RESTful service.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10102632" width="1" height="1"&gt;</description></item><item><title>re: Consuming REST/JSON services in Silverlight 4</title><link>http://blogs.msdn.com/b/carlosfigueira/archive/2010/04/29/consuming-rest-json-services-in-silverlight-4.aspx#10083764</link><pubDate>Sun, 31 Oct 2010 21:52:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10083764</guid><dc:creator>CarlosFigueira</dc:creator><description>&lt;p&gt;borice, in order to add the new header to the request, you&amp;#39;d use GetRequestClientFormatter to return an instance of a custom class (which implements IClientMessageFormatter), passing the original formatter used for the message. In the implementation of SerializeRequest, you would first call the original formatter to create the message object, and then set the Accept header in its properties, something similar to the code below:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Message result = this.originalFormatter.SerializeRequest(messageVersion, parameters);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;HttpRequestMessageProperty reqProp;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (result.Properties.ContainsKey(HttpRequestMessageProperty.Name))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;reqProp = (HttpRequestMessageProperty)result.Properties[HttpRequestMessageProperty.Name];&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;reqProp = new HttpRequestMessageProperty();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;result.Properties.Add(HttpRequestMessageProperty.Name, reqProp);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;reqProp.Headers[HttpRequestHeader.Accept] = &amp;quot;application/json&amp;quot;;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return result;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10083764" width="1" height="1"&gt;</description></item><item><title>re: Consuming REST/JSON services in Silverlight 4</title><link>http://blogs.msdn.com/b/carlosfigueira/archive/2010/04/29/consuming-rest-json-services-in-silverlight-4.aspx#10078675</link><pubDate>Wed, 20 Oct 2010 23:14:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10078675</guid><dc:creator>borice</dc:creator><description>&lt;p&gt;Carlos, thank you for the helpful code. &amp;nbsp;How would the code you&amp;#39;ve posted need to be modified if I want to be able to add the request header &amp;nbsp;&amp;quot;Accept: application/json&amp;quot; to any service method that has ResponseFormat = Json ? &lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10078675" width="1" height="1"&gt;</description></item></channel></rss>