0
我有Windows服务中运行的WCF服务。这工作正常,我能够发送/接收SOAP消息到服务器。我可以从同一个Windows服务托管一个WCF和WebService吗?
问题是我还希望能够从同一服务(或更具体地说来自同一端口,因此只有一个端口需要可以访问因特网)访问静态文件(简单下载)。
用我现有的服务,我有方法,如:
public interface IMyServerService
{
[OperationContract]
[WebInvoke]
string ListValue(string arg1);
}
现在我已尝试添加以下内容:
[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/DownloadFile")]
System.IO.Stream DownloadFile();
通过以下实现:
public System.IO.Stream DownloadFile()
{
var context = System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse;
context.Headers.Add(System.Net.HttpResponseHeader.CacheControl, "public");
context.ContentType = "text/plain";
context.StatusCode = System.Net.HttpStatusCode.OK;
return new System.IO.FileStream(@"C:\test.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read);
} // End of DownloadFile
我的目标是访问https://service/DownloadFile,但是当我尝试出现错误400时。
我想我的问题是,我能够从相同的WCF服务内做到这一点,还是应该创建第二个服务来做到这一点?