Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Indigo

File download through WCF/REST

 
 
Thread Tools Display Modes
Old 06-22-2007   #1 (permalink)
46N6984 programmer
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.

Old 06-26-2007   #2 (permalink)
novecento
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








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50