2012-02-24 67 views
3

我有一个WCF REST服务。我验证了Webconfig文件,并且所有配置项都很好。WCF REST Service EndPoint未找到WebInvoke错误

我得到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

+0

你可以发布你的配置和你尝试g的网址吗?等到WebGet方法? – CjCoax 2012-02-24 00:21:16

+0

看到我上面的编辑 – codematrix 2012-02-24 00:24:02

回答

2

我有以下代码:

[WebInvoke(ResponseFormat=WebMessageFormat.Json, RequestFormat= WebMessageFormat.Json)] 
string PostDateTimeAndReturnAsString(DateTime dateTime); 

上述方法的实现,如下图所示:

public string PostDateTimeAndReturnAsString(DateTime dateTime) 
{ 
     return dateTime.ToString(); 
} 

,如下图所示我的web.config:

<services> 
    <service name="XMLService.Service1" behaviorConfiguration="default"> 
      <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="RestBinding" name="Service1" contract="XMLService.IService1" /> 
    </service> 
</services> 
<behaviors> 
     <endpointBehaviors> 
    <behavior name="web"> 
     <webHttp /> 
    </behavior> 
</endpointBehaviors> 
</behaviors> 

我从小提琴手如下原始请求:

POST http://localhost/XMLService/Service1.svc/postdatetimeandreturnasstring HTTP/1.1 
User-Agent: Fiddler 
Content-Type: application/json 
Host: localhost 
Content-Length: 30 

"\/Date(1330081170513+0000)\/" 

我找回了一个HTTP 200 OK代码以下响应回:

"24\/02\/2012 11:07:59" 

注:当日期时间是需要的参数以原始请求格式显示(我使用的值是在我执行期间的当前日期时间,使用相同的值应该返回如下所示的值)的json格式传递,这是您需要传递它的方式

1

取下配置如下整个system.serviceModel

<?xml version="1.0"?> 
<configuration> 
<system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
</system.web> 

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
</system.webServer> 
</configuration> 

,我以为你的SVC文件已经是这样的:

<%@ ServiceHost 
       Language="C#" Service="SampleRest.Service1" 
       Factory="System.ServiceModel.Activation.WebServiceHostFactory" %> 

SVC自动执行中的配置system.serviceModel给你。

最后尝试http://localhost:65317/Service1.svc/

+0

谢谢,我试过这个,但也有同样的问题。 – codematrix 2012-02-24 00:55:55