问题
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>
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.
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.
What is wrong with my App.config file? How can i make those endpoints work?
As requested, the Interface:
[ServiceContract]
public interface IServiceOne
{
[OperationContract]
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "MyMethod")]
List<String> MyMethod();
}
回答1:
This article helped me set up my first WCF service, good read:
http://www.mikesknowledgebase.com/pages/Services/WebServices-Page1.htm
回答2:
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>
来源:https://stackoverflow.com/questions/19162996/iis-wont-activate-wcf-service-404-error