Welcome to MSDN Blogs Sign in | Join | Help

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

Published Tuesday, June 10, 2008 6:50 PM by rob.bagby
Filed under: , , ,

Comments

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

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

Friday, June 20, 2008 12:55 PM by wormster

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

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.

Thursday, June 26, 2008 6:33 PM by rob.bagby

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

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 again

John

Thursday, July 03, 2008 12:19 PM by wormster

# REST in WCF Blog Series Index

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

Thursday, August 07, 2008 2:03 PM by Demystifying The Code

# REST in WCF - Part VI (HI-REST - Consuming our GET service via AJAX)

In Part V of this blog series I completed the service operation exposed via HTTP GET in a HI-REST manner.

Friday, August 08, 2008 1:42 PM by Demystifying The Code

# REST in WCF - Part XI (Tunneling PUT through POST)

A common scenario you may encounter when designing your RESTful services is supporting clients that only

Monday, November 10, 2008 5:25 PM by Demystifying The Code

# REST in WCF

The series blog post on REST in WCF REST in WCF - Part I (REST Overview) REST in WCF - Part II (AJAX

Wednesday, December 24, 2008 1:34 AM by Journal of Abu Sayed Mohammad Ismail

# Exposing ATOM feeds from your services

One of the key enabling factors of the browsable web was the use of a standard representation format:

Wednesday, February 11, 2009 6:25 PM by Demystifying The Code

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

It's a very nice explained article about REST-WCF integration.

Thanks a lot Rob, it helped me out.

Tuesday, June 30, 2009 4:59 AM by Ulhas
Anonymous comments are disabled
 
Page view tracker