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.


