IIS无法激活WCF服务,出现404错误 [英] IIS won't activate WCF Service, 404 error
问题描述
我有一个仅会公开HTTP端点的WCF服务,我的App.config是这样的:
I have a WCF Service that will only expose HTTP Endpoints, my App.config is this:
<?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)运行到默认网站(项目应用程序).
I'm running IIS 7.5 (Windows 7 x64 - The full blown Programs and Features one, not Express) to the Default Web Site, the Project application.
我可以浏览到.svc文件,它会告诉我未启用MEX端点,这很好.当我尝试过帐到http://localhost/Project/ServiceOne/ServiceMethod
时,问题就来了.该方法存在于Service合同和实现中,并且在界面中也以WebInvoke的形式进行修饰,但是对其进行POST'ing将仅返回HTTP 404.用GET装饰测试方法并浏览到该方法会导致MapRequestHandler提供404服务.
I can browse to the .svc file and it will tell me the MEX endpoint is not enabled which is fine: It's the behavior i want over that aspect; The problem comes when i try to POST to http://localhost/Project/ServiceOne/ServiceMethod
. The method exists in the Service contract and implementation and is also decorated in the interface as a WebInvoke but POST'ing to it will only return HTTP 404's. Decorating a test method with GET and browsing to it results in a 404 served by MapRequestHandler.
我的App.config文件怎么了? 我该如何使这些端点正常工作?
What is wrong with my App.config file? How can i make those endpoints work?
根据要求,界面:
[ServiceContract]
public interface IServiceOne
{
[OperationContract]
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "MyMethod")]
List<String> MyMethod();
}
推荐答案
您需要设置适当的行为:
You need to setup proper behaviors:
<services>
<service name="Project.ServiceOne" behaviorConfiguration="serviceBehavior">
<endpoint address="" binding="webHttpBinding" contract="Project.IServiceOne" behaviorConfiguration="webBehaviour"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
<host>
<baseAddresses>
<add baseaddress="http://localhost/Project/ServiceOne">
</baseAddresses>
</host>
</service>
<service name="Project.ServiceTwo" behaviorConfiguration="serviceBehavior">
<endpoint address="" binding="webHttpBinding" contract="Project.IServiceTwo" behaviorConfiguration="webBehaviour"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
<host>
<baseAddresses>
<add baseaddress="http://localhost/Project/ServiceTwo">
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
这篇关于IIS无法激活WCF服务,出现404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!