我有一個WCF服務,它只會暴露HTTP終端,我的App.config是這樣的:IIS不會啓動WCF服務,404錯誤
<?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的64位 - 完整的程序和功能之一,而不是快速)到默認網站,項目應用程序。
我可以瀏覽到.svc文件,它會告訴我MEX端點未啓用,這很好:這是我想要的方面,問題出現在我嘗試POST到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
@RealityDysfunction發佈了簡化版本:界面中的所有方法都具有幾乎相同的配置相同的註釋 – Machinarius
我不熟悉與WCF通信的GET方法,因爲您經常需要調整UriTemplate才能使其工作,它實際上更容易讓它與POST方法一起工作。如果您將方法更改爲POST並取出UriTemplate並且仍然不起作用,那麼確實是web.config問題。 – RealityDysfunction