मैं इस के साथ घंटे के लिए लड़ाई लड़ी जब तक मैं अंत में इस उदाहरण का इस्तेमाल किया और यह पहली बार जाना काम: http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide
मैं जानता हूँ कि लिंक केवल जवाब अच्छा नहीं कर रहे हैं और अन्य लोगों के solve this type of problem here at Stackoverflow तो यहाँ हैं करने के लिए इस सी.पी. लिंक का इस्तेमाल किया है बुनियादी कदम अगर लेख कभी नीचे चला जाता है:
कदम 1
सबसे पहले दृश्य स्टूडियो 2010 क्लिक करें फ़ाइल> NEW-> परियोजना का शुभारंभ। नया "डब्ल्यूसीएफ सेवा आवेदन" बनाएं।
कदम 2
एक बार जब आप प्रोजेक्ट बनाते हैं, तो आप डिफ़ॉल्ट WCF सेवा और इंटरफ़ेस फ़ाइल से पहले से ही बनाए जाते हैं समाधान (Service1.cs & IService.cs) में देख सकते हैं। इन दो फाइलों को हटाएं और हम अपना इंटरफ़ेस और डब्ल्यूसीएफ सेवा फ़ाइल तैयार करेंगे।
कदम 3
समाधान पर अब सही क्लिक करें और एक नया WCF सेवा फ़ाइल बनाएँ। मैंने सेवा फ़ाइल को "RestServiceImpl.svc" नाम दिया है।
चरण 4
जैसा कि मैंने लेख है कि हम एक API जो एक्सएमएल और JSON प्रारूप में डेटा लौट सकते हैं लिख दिया जाएगा के शुरू में बताया गया है, कि यहाँ के लिए इंटरफेस है। IRestServiceImpl में, निम्न कोड
उपरोक्त कोड में, आप IRestService के दो अलग-अलग तरीकों को देख सकते हैं जो XMLData और JSONData हैं। एक्सएमएलडेटा एक्सएमएल में परिणाम देता है जबकि JSON में JSONData।
[ServiceContract]
public interface IRestServiceImpl
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "xml/{id}")]
string XMLData(string id);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "json/{id}")]
string JSONData(string id);
}
कदम 5
ओपन फाइल RestServiceImpl.svc.cs और वहाँ पर निम्नलिखित कोड लिखें:
public class RestServiceImpl : IRestServiceImpl
{
public string XMLData(string id)
{
return "You requested product " + id;
}
public string JSONData(string id)
{
return "You requested product " + id;
}
}
कदम 6
Web.Config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address ="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
</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>
</configuration>
चरण 7
आईआईएस में:
एक दूरस्थ सर्वर orlocalhost पर इस है? अगर रिमोट, क्या आपने सत्यापित किया है कि सब कुछ स्थानीय रूप से पहले काम करता है? –