【发布时间】:2017-01-20 02:38:33
【问题描述】:
我开发了一个 WCF 服务应用程序并将其部署到 IIS 8。
使用浏览器,当我转到http://localhost:6000/CustomService.svc 时,它显示 “您已创建服务”等信息。这意味着服务已成功部署。
但是当我转到 http://localhost:6000/testservice/date/2016/12/1 时,它显示 HTTP 404 Not Found。
这是服务合同:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
namespace WCF
{
[ServiceContract]
public interface ICustomService
{
[WebGet(UriTemplate = "date/{year}/{month}/{day}", ResponseFormat = WebMessageFormat.Xml)]
[OperationContract]
string GetDate(string day, string month, string year);
}
}
这里是实现类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WCF
{
public class CustomService : ICustomService
{
public string GetDate(string day, string month, string year)
{
return new DateTime(Convert.ToInt32(year), Convert.ToInt32(month), Convert.ToInt32(day)).ToString("dddd, MMMM dd, yyyy");
}
}
}
这里是 Web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="CustomServiceBehavior" name="WCF.CustomService">
<endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding" contract="WCF.ICustomService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:6000/testservice" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CustomServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
问题可能出在哪里?我基本上从https://weblogs.asp.net/kiyoshi/wcf-using-webhttpbinding-for-rest-services复制了大部分东西。
【问题讨论】:
标签: c# web-services wcf wcf-binding