2012-01-19 71 views
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服务内做到这一点,还是应该创建第二个服务来做到这一点?

回答

1

如果您设置了正确的绑定(例如您的新功能的webHttpBinding),您可以。问题是,如果你?通常,ServiceContract将特定功能组合在一起。如果这个文件下载是与现有服务无关的新东西,我会创建一个新文件。

相关问题