.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Question WCF Rest Service

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :Windows Application

Hi All,

I have question on WCF Rest Service, I have developed a WCF Rest Service and have two methods in it.

    [WebGet(UriTemplate = "GetInfo", ResponseFormat = WebMessageFormat.Xml)]   
    List<PersonalInfo> GetInfo();

    [WebInvoke(UriTemplate = "LoginUser/{UserId}",Method="Post", ResponseFormat = WebMessageFormat.Xml)]
    string LoginUser(string UserId);

First method uses WebGet ("GET") attribute and second method uses WebInvoke ("Post")

Question no 1:

           To test the first method I used IE and it is working fine. But how to test the second method, Is it true the at the second method cannot be tested     using IE?

Question no 2:

           Can we develop client application and add WCF rest service as Service refereces and test the functionality just like we do for other normal WCF      services?

            I tried but it is throwing so many errors!!!

Please clarify the above two questions?


View Complete Post

More Related Resource Links

Service Station: More On REST


This month's column answers frequently asked questions about implementing REST.

Jon Flanders

MSDN Magazine July 2009

Looking for a simple Service and Console Client REST sample implementing BASIC authentication


Does anyone know of a C# code sample demonstrating WCF REST services and console test client with OperationContracts (GET and POST) implementing mutiple paramaters using BASIC authentication? Also, perhaps, using Fiddler as a test client as well? I have searched high and low for something like this, but have not had any success.

Multiple services in REST Collection WCF Service?


After I create a "REST Collection WCF Service" project, it contains one service "service.svc". Can I add multiple services to this project? There must be a way to do so. Otherwise, it does not make sense to create one project for each service.


My question is how to add a new service to an existing "REST Collection WCF Service" project?


Thanks a lot.

web service soap mapper error question

Hi,I'm trying to connect to a web service using excel.I have currently no issues logging into the web service, and running one of the other functions to fetch a full list of data.  Once I am able to log in, the function returns a token, which I use to fetch data.But Currently, I'm getting the following errors one two of the functions:SoapMapper:Restoring data into SoapMapper ViewListResult failed HRESULT=0x80020009: Exception occurred. - Client:Unspecified client error. HRESULT=0x80020009: Exception occurred.Run-time error '-2147221504 (80040000)':SoapMapper:Restoring data into SoapMapper ViewListResult failedAny idea why I might be getting this error?  And also how I can fix it?  Thanks.

Serializing Linq to Entities for use in a REST Service

What would be the best approach to send data retrieved from Linq to Entities over a rest service? For example, if you have a Linq to Entities class, say Products from the Northwind database. I want to return a subset of the Products (based on a query on the model) back through a service. First a retrieve a List<Product> from the context, and then i need to serialize the data and send it over the wire. If I use the exact Linq to Entities class, then there is so much "garbage" that it either fails outright (from a circular reference) or you are wasting bandwith. What is a design to overcome this? Create POCO objects for each linq to entities class you want to send and create custom code to tranform each object in the list to the POCO object? This is the only way I can see doing it, although it would be very tedius to create and maintain (unless some custom code generation was created). Is there a better approach? clients

Question about WCF Service hosted in Windows Service

Hi, I have little experience with WCF and working on a projet that requires WCF Service instance to run 24x7. After searching for a solution and reading about WCF, I think if I host it under Windows Service I can have a single instance of WCF Service running 24x7. Is this correct? I just successfully ran the MSDN sample project that hosts CalculatorService in Windows Service. I realized that Windows Service cannot communicate with WCF Service it is hosting (I do not have any experience with writing Windows Service). I wrote a test function (public) in Windows Service and tried to call it from WCF Service but it did not appear in the Intellisense list. Is my assumption correct or is there a way to establish communication between Windows Service and its hosted WCF Service? Thanks. kr

System.ComponentModel.DescriptionAttribute not showing up in REST service

I am trying to set the description for a REST WCF service, but it doesn't seem to be working. Code is: [AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]     [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]     [WebDispatchFormatterConfiguration("application/xml")]     [WebDispatchFormatterMimeType(typeof(WcfRestContrib.ServiceModel.Dispatcher.Formatters.PoxDataContract), "application/xml", "text/xml")]     [WebDispatchFormatterMimeType(typeof(WcfRestContrib.ServiceModel.Dispatcher.Formatters.DataContractJson), "application/json")]     [WebDispatchFormatterMimeType(typeof(WcfRestContrib.ServiceModel.Dispatcher.Formatters.FormUrlEncoded), "application/x-www-form-urlencoded")]     public class PublicAppointmentSchedulerSvc : IPublicAppointmentScheduler     {         IPublicAppointmentScheduler impl = new PublicAppointmentScheduler();         [WebDispatchFormatter]         [Description("Immediate or callback contact request")]         [WebInvoke(UriTemplate = "InitiateContact", Method = Verbs.Post)]  &n

GoDaddy + WCF REST Service

I am newbie when it comes to developing a WCF REST Service. I have been reading up and have worked through hands-on labs/watched videos by Ron Jacobs to help me get a hold of WCF REST.  I have had no problems running my web service on my localhost. However it is now time to upload my "WCF Service Application" (not WCF Library) to GoDaddy's servers and this is where I am running into issues. As per Ron Jacobs tutorials I have removed my endpoints from my web.config file and the markup code in my .svc file now reads: <%@ ServiceHost Language="C#" Debug="true" Service="DealService.Service" CodeBehind="Service.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory"%> I proceeded to compile and then upload my code to GoDaddy and now am trying to access the web service, but am receiving the following error: Server Error in '/' Application. Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.  Parser Error Message: The CLR Type 'System.ServiceModel.Activation.WebServiceHostFactory' could not be loaded during service compilation. Verify that this type is either defined in a source file located in the application's \App

ASP.Net Client for Php REST Service

 I am writing some code in an asp application that needs to communicate with a PHP REST Service. I have 2 questions. 1.  In my data variable I have to put the POST parameters.  If I needed to put reserved characters like & or ? into the string is there an escape character I can use?  Or would encoding it work?  Or would it totally depend on how the web service works? 2.  Is the code I am using the usual way to make a POST connection to a REST service?  Or is there an easier/faster way? Below is the code I am using Dim uri As New Uri("http://help.domain.com/api/index.php?method=request.create") Dim data As String = "tNote=Testing Code&sEmail=test@test.com" If uri.Scheme = uri.UriSchemeHttp Then Dim request As HttpWebRequest = HttpWebRequest.Create(uri) request.Method = WebRequestMethods.Http.Post request.ContentLength = data.Length request.ContentType = "application/x-www-form-urlencoded" Dim writer As New StreamWriter(request.GetRequestStream) writer.Write(data) writer.Close() Dim oResponse As HttpWebResponse = request.GetResponse() Dim reader As New StreamReader(oResponse.GetResponseStream()) Dim tmp As String = reader.ReadToEnd() oResponse.Close()

SQL Server 2008 R2 Installation and Service Pack 1 Question

I am migrating a SQL 2000 server to a SQL 2008 R2 server (on different physical servers) . When I ordered SQL Server 2008 the volume licensing allowed me to download sql server web 2008, sql server web 2008 R2 and sql server 2008 service pack 1. I don't know why I have three options to download. Don't I just need to just install the sql server 2008 Web R2? Are there any sql 2008 R2 service packs available?   

PUT method gives error 400 "Bad Request" in WCF REST Service Application

I am trying to learn WCF REST Services through http://blogs.msdn.com/endpoint/archive/2010/01/14/updating-state-in-wcf-webhttp-services.aspx , It's a link of Part 3 of 12 part blog series. Now I am trying the same stuff given in the part 3 with my own Entities and Entity Model instead of what is given in the blog. Here is my full project I am working on .. http://cid-9e3f62c0688824b0.skydrive.live.com/self.aspx/.Public/pronerveEPMS.zip For comparision with the code shown in the Blog I am following, you can download the zip file of the project from the same link given here at starting (At the end of the blog and before comments starts). And here is the method in Program.cs file of console project in my application that raises the exception.....        private static Role UpdateRole(HttpClient hc, Role role1)        {            Console.WriteLine("Updating Role {0} : ",     role1.RoleID);            Console.WriteLine();            string updateURI = "Roles/" + role1.RoleID.ToString();            HttpContent content = HttpContentExtensions.CreateDataContract(role1);            using (HttpResponseMessage response = hc.Put(upd

How to remove .svc from URL in REST service with WCF 3.5 on IIS 7

Hi, I'm using REST WCF3.5 with JSON as output. My URL to delete person info is http://localhost/RestService/RestService.svc/myproject/persons/3  I'm using IIS7 in Windows Server 2008. How do I get rid of .svc extension in the URL so that client can use URL like http://localhost/RestService/myproject/persons/3 ? Thanks!

host and consume wcf rest service in web project in single solution

I have  create a solution which have multiple class library project and a web application Like Web(UI),BL,DAL etc. I have also add a WCF REST starter kit Collection project in the same Solution.WCF Rest API is working fine if I host it on IIS but i want to consume this in my web project without using IIS. Is this possible? if yes then what will be the URI  for my WCF Rest services? Add service reference is also not working because WSDL is disable in rest.

Infopath 2010 cannot connect to Rest web service

Hi all, I recently tried to access an Excel spreadsheet range as a Rest web service in Infopath 2010; no luck.  Here are the steps I followed: 1. [Successful] Upload Excel spreadsheet with the said ranges onto a Sharepoint document library 2. [Successful] Bind the Excel spreadsheet range (I have one called Regions) in the Sharepoint document library as a Rest web service in Infopath form's listbox control during design time as follows - http://mosscrm/sites/sandbox/_vti_bin/excelrest.aspx/eventbudgets/lookups.xlsx/model/ranges('Regions')?$format=atom 3. [Failed] Then I tried to preview the form, but the actual data in the Excel range failed to populate the Infopath listbox control.  The error I got was: "Could not open "http://<localhost>/sites/<site name>/_vti_bin/ExcelRest.aspx/EventBudgets/Lookups.xlsx/Model/Ranges('EventTypes')?$format=atom"   The error I then got from Infopath was a pop-up saying: The query cannot be run for the following DataObject: Event Types InfoPath cannot run the specified query. The file is not a valid XML file. Not enough storage is available to process this command . If anyone out there has experienced a similar issue and resolved it, please kindly share your solution approach. Thanks.

Question on WCF service with Linq to SQL on 64-bit system

I'm trying this question one more time since I realized the work in in a 64-bit environment. I have a WCF service which runs in production in a 32-bit environment using VS2008 and .NET 2.0. We made a big change to our environment (lots at the same time) and I moved the services to VS2010, .NET 4.0, and 64-bit processes.  I wrote a new service and deployed it under IIS.  If I browse to the service I get the example screen and clicking on the link gives me the metadata.  So all of that is working. In my services I create a Linq to SQL context, perform a query, then return the result set as an Array.  I wrapped the context creation with a using.  My tests returned an exception "Attempt to access an object that has already been disposed".  I traced it down and found that the code executes, forces the query, returns the results, exits the using statement (disposing the context properly) then exits the method.  The next thing I get is the exception, inside framework code, and it is linq code attempting to fulfill the query once again. I have searched until I'm blue in the face trying to find prior incidents and fixes but all I found was one post, two years ago, same problem with less debugging, and no answer to the problem other than 'don't use the using statement' which is a bad suggestion.  So for a work around I wrote a Co

REST Web service,not getting response


Hi ,

I have to call a REST web service method that is deployed remotely on a machine and i use VPN to connect through that url. It works fine when i use the browser to view the output of the web service method but i am unable to get the response in the code as i get an exception. The response status message is OK but when i try to read the response content from the streamreader i get the exception "ex = {"Unable to read data from the transport connection: The connection was closed."}". The content length is -1 in the HttpWebReponse object. Here is the code

        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("");

        //apply this url when working with the software
       // HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://localhost:1901/metascan_rest/scanner?method=getengineinfo");
        request.Method = "GET";
        WebResponse res = request.GetResponse();

        string status = ((HttpWebResponse)res).StatusDescription;

        Stream stream = res.GetResponseStream();
        StreamReader reader = new StreamReader(stream);

          //this is where the exception occurs
            string output = reader.ReadToEnd();

How WCF 4 REST Service Support Form Post As Well As XML and JSON?


Using the rest 4 template.  I have a POST method defined, with an object as a parameter.  REST 4 does a great job of automatically mapping both xml and json posts to the method.  I tested this using an HttpClient test application to build and post xml content and then json content. 

I want to also support a standard form post to the method but am having problems!  

I'd like the same method already accepting and converting both xml and json to also work correctly for a form post.  I am testing this by creating an HttpUrlEncoded form in the test client, adding form name/value pairs that match what the method is expecting, and trying to post it.

However I get a 400 Bad Request.  Here's some example code that is returning a 400 bad request:

            var client = new HttpClient();

            HttpUrlEncodedForm form = new HttpUrlEncodedForm();
            form.Add("Id", "99");
            form.Add("Message", "Message test with 'special' chars #!#");
            form.Add("IpAddress", "");

            var response = client.Post("<valid-uri-here>", form.CreateHttpContent());

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend