![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | 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. |
My System Specs![]() |
| | #2 (permalink) |
| | 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. > |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Where is the rest of my file? | Vista music pictures video | |||
| in vb.net how to open a file from file download prompt without askinguser to save it or run it....just open it in internet explorer | .NET General | |||
| Where's the rest of my Ram? | Vista General | |||
| IE7 Save File option ceases to appear after multiple file download | Vista General | |||
| download file becomes Winrar file | Vista installation & setup | |||