xoa*_*ail 5 .net c# asp.net wcf
我正在尝试将wcf restful服务添加到我现有的asp.net 4.0网站(不是mvc).我发现很难找到一个好的教程,通过添加一个现有的应用程序/网站.我看到的每个地方都有关于创建新项目的注释(使用wcf restful模板).基本步骤是什么?我可以在没有.svc文件的情况下这样做,因为我在.net 4.0上吗?您可以指点我的任何教程?
到目前为止,我已经尝试添加定义服务契约的IService.cs和Service.cs类,并使用webinvoke/webget属性,在web.cong中添加global.asax中的路由和web.cong中的服务定义,如本教程所示:http:// www .codeproject.com/Articles/255684/Create-and-Consume-RESTFul-Service-in-NET-Framewor但是当我指向localhost/restservice时,我找不到404.
更新:这是我在配置文件中的内容.请注意,这是一个现有的基于wcf soap的服务.
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="migrationServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="migrationHttpBinding" maxBufferSize ="104857600" maxReceivedMessageSize="104857600"/>
</basicHttpBinding>
</bindings>
<services>
<service name ="Site.Web.WebService.MigrationService" behaviorConfiguration="migrationServiceBehavior">
<endpoint binding="basicHttpBinding"
bindingConfiguration="migrationHttpBinding"
contract="Site.Web.WebService.IMigrationService"/>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
您不需要任何*.svcWCF REST服务文件 - 您可以使用以下命令激活它ServiceRoute- 请参阅没有svc文件的RESTful WCF服务和无配置以获得很好的解释.
基本上它归结为ServiceRoute在你的路由表中添加一个global.asax:
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(),
typeof(YourService)));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6910 次 |
| 最近记录: |