Windows Vista Forums

File download through WCF/REST
  1. #1


    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.

      My System SpecsSystem Spec

  2. #2


    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.
    >


      My System SpecsSystem Spec

File download through WCF/REST problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
File System - XP,Vista - File Redirector - Download abc Vista file management 1 02 Mar 2010
Where is the rest of my file? Xplaya Vista music pictures video 5 10 Jul 2008
Where's the rest of my Ram? G Vista General 9 27 May 2007
IE7 Save File option ceases to appear after multiple file download beaubrad Vista General 3 06 Mar 2007
download file becomes Winrar file =?Utf-8?B?Unlhbg==?= Vista installation & setup 1 17 Sep 2006