使用Stream的ASP Rest服务

时间:2014-03-24 12:52:36

标签: c# asp.net rest

我正在尝试使用Stream输入构建REST服务,我最终希望将其保存在服务器上的文件中。我的问题是,当我运行服务时,我得到了“未找到EndPoint”

我正在使用VS 2010和.NET 4.0

我的服务模式如下

<services>
  <service name="WCFService1.TestService" behaviorConfiguration="ServiceBehaviour">
    <endpoint address=""
              binding="webHttpBinding"
              contract="WCFService1.ITestService"
              behaviorConfiguration="web" />
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaviour">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp/>
    </behavior>
  </endpointBehaviors>      
</behaviors>

此阶段的代码非常简单。 服务代码

namespace WCFService1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]

  public interface ITestService
  {
    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "UploadFile/{fileName}", BodyStyle = WebMessageBodyStyle.Bare)]
    Stream UploadFile(string fileName, Stream fileContents);
  }
}

功能实现

    public Stream UploadFile(string fileName, Stream fileContents)
    {
        //save file
        var sr = new StreamReader(fileContents);
        string text = sr.ReadToEnd();
        return new System.IO.MemoryStream(Encoding.UTF8.GetBytes("Hello World! " + text + fileName));
    }

svc文件

<%@ ServiceHost Language="C#" Debug="true" Service="WCFService1.TestService"   CodeBehind="TestService.svc.cs"   Factory="System.ServiceModel.Activation.WebServiceHostFactory"%>

我做错了什么?

0 个答案:

没有答案