【发布时间】:2013-10-10 09:01:27
【问题描述】:
我有一个只会公开 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();
}
【问题讨论】:
-
你能给我们看看你的装饰界面吗?
-
@RealityDysfunction 发布简化版:接口中的所有方法都有相同的注解,配置方式几乎相同
-
我不熟悉与 WCF 通信的 GET 方法,因为您经常需要调整 UriTemplate 才能使其工作,实际上使用 POST 方法更容易使其工作。如果您将方法更改为 POST 并取出 UriTemplate,但它仍然无法正常工作,那么确实是 web.config 问题。
-
之前是 POST,我把它变成了 GET,所以我可以用普通浏览进行测试
-
我认为您不能以这种方式设置端点地址并发布到该 URL。 RESTful WCF 仍然需要在 URL 中有 .svc,然后您可以使用 URL rewrite 删除 .svc。