我有一个WCF REST服务。我已经验证了Webconfig文件,并且所有的配置项都是正确的。
我使用以下代码,但是出现了“EndPoint未找到”的错误。我将向GetDateTime方法添加参数。
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
string GetDateTime();
使用以下代码出现了“无终端点”错误。
[OperationContract]
[WebGet(UriTemplate = "/")]
string GetDateTime();
我希望能够通过WebInvoke使其运行起来。非常感谢您的帮助!
以下是Web.config文件的配置细节。
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="SampleRest.Service1" behaviorConfiguration ="ServiceBehaviour">
<endpoint address="" binding ="webHttpBinding" contract="SampleRest.IService1" behaviorConfiguration ="web" >
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
这是我尝试的URL。
http://localhost:65317/Service1.svc
(注:该内容已经是中文,无需翻译)