![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | File download through WCF/REST I'm trying to provide file download using REST/WCF. Scenario is: Type a url like http://localhost:8020/test in a browser, a dialog should pop up for saving the file. I tried using MTOM with basicHttpBinding and customBinding. I can get a soap response in the browser, but no attachment. I tried using MessageVersion.None to strip soap content, but of no use. My code is like this: [ServiceContract] public interface IUniversalContract { [OperationContract(Action = "*",ReplyAction="*")] Message ProcessMessage(Message input); } Implemented method is: public Message ProcessMessage(Message input) { Message outgoing = null; Stream stm = null; try { stm = new FileStream("EntireRun.ssr",FileMode.Open,FileAccess.Read); XmlDictionaryReader rdr = XmlDictionaryReader.CreateMtomReader(stm, Encoding.Unicode, new XmlDictionaryReaderQuotas()); MessageVersion ver = MessageVersion.Soap12WSAddressing10; outgoing = Message.CreateMessage(ver, "GETResponse", rdr); HttpResponseMessageProperty response = new HttpResponseMessageProperty(); response.StatusCode = HttpStatusCode.OK; response.Headers.Add("Content-disposition", "attachment;filename=run.bbt"); outgoing.Properties[HttpResponseMessageProperty.Name] = response; } catch (Exception) { if (stm != null) stm.Close(); } return outgoing; } I get a save file dialog, but the content is not that of the file. It includes the following: --------------------------------------------------------------------------------------------------------------------------------------------------------- --uuid:61dcdcbe-8dd0-4eac-8a7b-aff923169b39+id=1 Content-ID: <http://tempuri.org/0> Content-Transfer-Encoding: 8bit Content-Type: application/xop+xml;charset=utf-8;type="application/soap +xml" <s:Envelope xmlns="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"> <s:Header> <a:Action s:mustUnderstand="1">GETResponse</a:Action> </s:Header> <s:Body> <s:Envelope> <s:Body/> </s:Envelope> </s:Body> </s:Envelope> --uuid:61dcdcbe-8dd0-4eac-8a7b-aff923169b39+id=1-- --------------------------------------------------------------------------------------------------------------------------------------------------------------- My config file is: ------------------------------------------------ <customBinding> <binding name="mtomhttp"> <mtomMessageEncoding /> <httpTransport transferMode="StreamedResponse"/> </binding> </customBinding> Can someone please tell me if providing file download in a browser through WCF without IIS is possible at all? I should be able to type in a URL in browser and download a file. Thanks in advance. |
| | #2 (permalink) |
| Guest | Re: File download through WCF/REST Is possible that XmlDictionaryReader.CreateMtomReader can't open a stream correctly ? "46N6984 programmer" <civaprasad@gmail.com> wrote in message news:1182572098.705412.92260@k79g2000hse.googlegroups.com... > I'm trying to provide file download using REST/WCF. Scenario is: Type > a url like http://localhost:8020/test in a browser, a dialog should > pop up for saving the file. I tried using MTOM with basicHttpBinding > and customBinding. I can get a soap response in the browser, but no > attachment. I tried using MessageVersion.None to strip soap content, > but of no use. My code is like this: > > [ServiceContract] > > public interface IUniversalContract > { > [OperationContract(Action = "*",ReplyAction="*")] > Message ProcessMessage(Message input); > } > > Implemented method is: > > public Message ProcessMessage(Message input) > { > Message outgoing = null; > > Stream stm = null; > > try > > { > > stm = new FileStream("EntireRun.ssr",FileMode.Open,FileAccess.Read); > > XmlDictionaryReader rdr = XmlDictionaryReader.CreateMtomReader(stm, > Encoding.Unicode, new XmlDictionaryReaderQuotas()); > > > MessageVersion ver = MessageVersion.Soap12WSAddressing10; > > outgoing = Message.CreateMessage(ver, "GETResponse", rdr); > > HttpResponseMessageProperty response = new > HttpResponseMessageProperty(); > > response.StatusCode = HttpStatusCode.OK; > > response.Headers.Add("Content-disposition", > "attachment;filename=run.bbt"); > > outgoing.Properties[HttpResponseMessageProperty.Name] = response; > > } > catch (Exception) > { > if (stm != null) > stm.Close(); > } > return outgoing; > } > > I get a save file dialog, but the content is not that of the file. It > includes the following: > --------------------------------------------------------------------------------------------------------------------------------------------------------- > --uuid:61dcdcbe-8dd0-4eac-8a7b-aff923169b39+id=1 > Content-ID: <http://tempuri.org/0> > Content-Transfer-Encoding: 8bit > Content-Type: application/xop+xml;charset=utf-8;type="application/soap > +xml" > > <s:Envelope xmlns="http://www.w3.org/2003/05/soap-envelope" > xmlns:a="http://www.w3.org/2005/08/addressing"> > <s:Header> > <a:Action s:mustUnderstand="1">GETResponse</a:Action> > </s:Header> > <s:Body> > <s:Envelope> > <s:Body/> > </s:Envelope> > </s:Body> > </s:Envelope> > --uuid:61dcdcbe-8dd0-4eac-8a7b-aff923169b39+id=1-- > --------------------------------------------------------------------------------------------------------------------------------------------------------------- > > My config file is: > ------------------------------------------------ > <customBinding> > <binding name="mtomhttp"> > <mtomMessageEncoding /> > <httpTransport transferMode="StreamedResponse"/> > </binding> > </customBinding> > > Can someone please tell me if providing file download in a browser > through WCF without IIS is possible at all? I should be able to type > in a URL in browser and download a file. > > Thanks in advance. > |
| |
| |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Where is the rest of my file? | Xplaya | Vista music pictures video | 5 | 07-10-2008 10:19 PM |
| SP1 for the rest of the world | storsett | Windows Updates | 0 | 03-29-2008 06:41 AM |
| Where's the rest of my Ram? | G | Vista General | 9 | 05-27-2007 12:21 PM |
| IE7 Save File option ceases to appear after multiple file download | beaubrad | Vista General | 3 | 03-06-2007 07:47 PM |
| download file becomes Winrar file | =?Utf-8?B?Unlhbg==?= | Vista installation & setup | 1 | 09-17-2006 09:57 AM |