2012-02-24 65 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