我有一个只会公开 HTTP 端点的 WCF 服务,我的 App.config 是这样的:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "C:\Users\Developer\Documents\ProjectName\Servicelog.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" />
<services>
<service name="Project.ServiceOne">
<endpoint address="http://localhost/Project/ServiceOne" binding="webHttpBinding" contract="Project.IServiceOne"/>
</service>
<service name="Project.ServiceTwo">
<endpoint address="http://localhost/Project/ServiceTwo" binding="webHttpBinding" contract="Project.IServiceTwo"/>
</service>
</services>
</system.serviceModel>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept"/>
</customHeaders>
</httpProtocol>
</system.webServer>
<startup>
<supportedRuntime version="v2.0.50727" />
</startup>
</configuration>
我正在将 IIS 7.5(Windows 7 x64 - 完整的程序和功能一,而不是 Express)运行到默认网站,即项目应用程序。
我可以浏览到 .svc 文件,它会告诉我未启用 MEX 端点,这很好:这是我想要在这方面的行为;当我尝试发布到http://localhost/Project/ServiceOne/ServiceMethod
. 该方法存在于服务合同和实现中,并且在接口中也被装饰为 WebInvoke,但对其进行 POST 只会返回 HTTP 404。使用 GET 装饰测试方法并浏览它会导致 MapRequestHandler 提供 404。
我的 App.config 文件有什么问题?我怎样才能使这些端点工作?
根据要求,界面:
[ServiceContract]
public interface IServiceOne
{
[OperationContract]
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "MyMethod")]
List<String> MyMethod();
}