2011-11-30 19 views
6

मैं एक बुनियादी बाकी वेब सेवा केवल वर्तमान समय रिटर्न का निर्माण करने की कोशिश कर रहा हूँ और जब भी मैं मैं निम्न त्रुटि प्राप्त करने की कोशिश मैं अपने सेवा http://localhost:PORT/TimeService/CurrentTime फोन करने की कोशिश जब भी:RESTful वेब सेवा समाप्ति बिंदु नहीं मिला

एंडपॉइंट नहीं मिला। सेवा के लिए वैध अनुरोधों के निर्माण के लिए कृपया सेवा सहायता पृष्ठ देखें।

मैं क्या गलत कर रहा हूं? नीचे आप मेरे द्वारा उपयोग किए जा रहे सभी कोड पा सकते हैं। धन्यवाद

Service1.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.ServiceModel; 
using System.ServiceModel.Activation; 
using System.ServiceModel.Web; 
using System.Text; 

namespace WcfRestService1 
{ 
    [ServiceContract] 
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] 
    public class TimeService 
    { 
     [WebGet(UriTemplate = "CurrentTime")] 
     public string CurrentTime() 
     { 
      return DateTime.Now.ToString(); 
     } 
    } 
} 

Global.asax

using System; 
using System.ServiceModel.Activation; 
using System.Web; 
using System.Web.Routing; 

namespace WcfRestService1 
{ 
    public class Global : HttpApplication 
    { 
     void Application_Start(object sender, EventArgs e) 
     { 
      RegisterRoutes(); 
     } 

     private static void RegisterRoutes() 
     { 
      RouteTable.Routes.Add(new ServiceRoute("TimeService", 
       new WebServiceHostFactory(), typeof(TimeService))); 
     } 
    } 
} 

web.config

<?xml version="1.0"?> 
<configuration> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 

    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
    </modules> 
    </system.webServer> 

    <system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
    <standardEndpoints> 
     <webHttpEndpoint> 
     <!-- 
      Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
      via the attributes on the <standardEndpoint> element below 
     --> 
     <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/> 
     </webHttpEndpoint> 
    </standardEndpoints> 
    </system.serviceModel> 

</configuration> 
+2

मैं हाथ नहीं पता है कि अगर execption का कारण बनता है, लेकिन आप '[OperationContract]' मौजूदा समय विधि –

+0

पर विशेषता .NET 4.0 जब से तुम [OperationContract की जरूरत नहीं है लापता नहीं कर रहे हैं ] अब यदि आपके पास डब्ल्यूसीएफ HTTP सेवाओं के लिए [WebGet] या [WebInvoke] है। – carlosfigueira

+0

किस vdir/application global.asax स्थित है? यदि यह सीधे आईआईएस रूट पर नहीं है, तो पता http: // localhost होना चाहिए: पोर्ट/एप्लिकेशन नाम/टाइम सेवा/CurrentTime – carlosfigueira

उत्तर

4

यह सबसे अच्छा लेख मैंने पाया जब मैं पहली बार सीखने शुरू कर दिया में से एक है आराम; काश मैं काम पर था अब मेरे पास सही समय सेवा उदाहरण है लेकिन मैं सिर्फ गुगल हूं और एक ही कोड नहीं मिला।

कल से काम करने पर मैं एक कामकाजी उदाहरण पोस्ट करूंगा यदि आपको अभी भी इसकी आवश्यकता है।

http://geekswithblogs.net/michelotti/archive/2010/08/21/restful-wcf-services-with-no-svc-file-and-no-config.aspx

+1

यदि आप इसे पोस्ट कर सकते हैं तो यह बहुत उपयोगी होगा। – atrljoe

संबंधित मुद्दे