REST in WCF - Part V (HI-REST - Exposing a service via GET - The ServiceContract and Implementation)

The post on building a HI-REST GET with WCF has been moved to my new blog at www.robbagby.com.

image

Comments

  • Anonymous
    June 20, 2008
    Hi Rob I am trying to implement an interface for the service contract:- namespace Medquist {    [ServiceContract(Namespace = "WCFServices")]    public interface IXDomainService    {        [OperationContract]        [WebGet(ResponseFormat = WebMessageFormat.Json)]        Medquist.PatientData SearchPAS(string userSessionId, string patientID, string patientDoB);    } } and the service... namespace Medquist {    public class XDomainService : IXDomainService    {        public PatientData SearchPAS(string userSessionId, string patientID, string patientDoB)        { ........ config file :-        <services>            <service name="XDomainService">                <endpoint address="" behaviorConfiguration="XDomainServiceAspNetAjaxBehavior"                 binding="webHttpBinding" contract="IXDomainService" />            </service>        </services> However the proxy in the AJAX javascipt cannot resolve the namespace var proxy = new WCFServices.XDomainService();    proxy.SearchPAS(...... I have specified Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" in the .svc file. Am I missing something else? Without the interface and all the attributes in place, everything works fine. John

  • Anonymous
    June 26, 2008
    John,If you set the WebScriptServiceHostFactory in the svc, your configurations will be ignored (or an exception will be thrown).  It automatically configures the webHttpBinding with the enableWebScript endpoint behavior.  If you omit this, you would need to add an endpoint behavior configured in the web.config.  Something like this:<system.serviceModel>   <behaviors>     <endpointBehaviors>       <behavior name="XDomainServiceAspNetAjaxBehavior">         <enableWebScript />       </behavior>     </endpointBehaviors>   </behaviors>...In either case, you also need to have a ScriptManager in your page with a service path configured:       <asp:ScriptManager ID="scriptManager" runat="server">            <Services>               <asp:ServiceReference Path="~/YourPathToYourSvc.svc" />           </Services>       </asp:ScriptManager>The best way to check to make sure you have everything is to rt-click the page and View Source.  Look for the <script element that has "YourSvcFile.svc/js" or "YourSvcFile.svc/jsdebug".  Copy that relative path to the address bar of the browser (if your svc file and page are at the root, simply replace the YourPage.aspx with YourService.svc.  If you are prompted with a dialog to save the proxy file (it is javascript), you are in business.  if not, Houston, there is a problem.

  • Anonymous
    July 03, 2008
    Thanks, Rob.The service file js indicated that the proxy was using the Interface, IXDomainService in the name space  - I didn't realise that. Changing the proxy to...var proxy = new WCFServices.IXDomainService();...resolved the issue.Thanks againJohn

  • Anonymous
    August 07, 2008
    As some of you know, I am in the midst of a blog series on REST in WCF. Further, I have been hard at

  • Anonymous
    August 08, 2008
    In Part V of this blog series I completed the service operation exposed via HTTP GET in a HI-REST manner.

  • Anonymous
    November 10, 2008
    A common scenario you may encounter when designing your RESTful services is supporting clients that only

  • Anonymous
    December 23, 2008
    The series blog post on REST in WCF REST in WCF - Part I (REST Overview) REST in WCF - Part II (AJAX

  • Anonymous
    February 11, 2009
    One of the key enabling factors of the browsable web was the use of a standard representation format:

  • Anonymous
    June 29, 2009
    It's a very nice explained article about REST-WCF integration.Thanks a lot Rob, it helped me out.