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

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

Need help with Restful WCF service and tester

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :WCF
Greetings,  I need a simple restful service to upload an image.   I am new to restful services and this is my attempt to create a simple service and tester.  I cannot get this to work.  Like I said I am new and I would appreciate any help.  Thanks. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Net; using System.ServiceModel; using System.ServiceModel.Web; namespace ImageTester { [ServiceContract] public interface IImageTestService { [OperationContract, WebInvoke(Method = "POST",UriTemplate = "File/{fileName}")] bool UploadFile(string fileName, Stream fileContents); } [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] public class ImageTestService : IImageTestService { public bool UploadFile(string fileName, Stream fileContents) { return true; } } class Program { static void Main() { Uri baseAddress = new Uri("http://localhost:8889/TestImage"); WebServiceHost host = new WebServiceHost(typeof(ImageTestService), baseAddress); try { host.Open(); Console.WriteLine(host.BaseAddresses[0].AbsoluteUri + " running.\n"); Console.WriteLine("hit a key to send image&quo

View Complete Post

More Related Resource Links

Service Station: Building RESTful Clients


This column how to build clients applications based on the REST architecture using HTTP AP1s. The article describes how to address the question of autogenerated types and code.

Jon Flanders

MSDN Magazine October 2009

Service Station: An Introduction To RESTful Services With WCF


We discuss some of the basic tenets of REST as well as present an implementation of a RESTful service using WCF.

Jon Flanders

MSDN Magazine January 2009

RESTful WCF Workflow Service

Folks,   I'm in the middle of building a service (.xamlx) that is basically going to support a document submission workflow. Via the web service, I want clients to be able to POST a big ol' XML file into my system. This is going to kick off a big, long-running, persistable, AppFabric-managed workflow. Clients will be able to poll this (or another) service to get the status of the document processing.   My issue right now is that it appears as though, out of the box, what I get is straight-up WSDL-style services that use standard web service tactics. I was wondering if there was something I could do, either via web.config or via the workflow designer, that would allow me to have my WCF-hosted workflow AND have the endpoint be a RESTful (or even REST-ish... i'm not picky) one. In other words, I want to be able to POST an arbitrary blob of XML to my workflow service (complete with authentication tokens in custom HTTP headers). Is this possible? If so, how?The .NET Addict - http://dotnetaddict.dotnetdevelopersjournal.com

How to add XML documentation to generated Schema for a RESTful service

I'm using the RESTful Starter Kit which automatically generates a Service help page. For each method there is a link to a Request Schema. How can I add documentation/comments for each DataMember in the DataContracts so that the description/comment shows up in the generated xml schema?

RESTful WCF Service endpoint not being found by client


I created a RESTful WCF service which I plan to call from a client app (a custom toolpart in a Sharepoint web part), but while I can access everything just fine from a browser the client throws this error:

EndpointNotFoundException: There was no endpoint listening at http://mymachine:3217/Services/CtmsService.svc that could accept the
message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
---> System.Net.WebException: The remote server returned an error: (404) Not Found.

My service's contract looks like this:

public interface ICtmsService
  [WebGet(UriTemplate = "/GetAllSites")]
  Dictionary<string, int?> GetAllSites();
...and the configuration looks like this: (which is more complicated due to needing dependency injection via Spring.NET to work)


How to enable windows authentication for a RESTFul web service which is not hosted in IIS


I have created a WCF RESTFul webservice by following http://msdn.microsoft.com/en-us/library/dd203052.aspx. I am hosting my RESTful webservice in a window service (and not IIS) using the WebServiceHost class. 

Now I am struggling to get user's windows credentials in my web service methods. I looked at various code samples in forums for this. Almost all of them are hosting the service in IIS plus configuring  the service's settings using <system.serviceModel> tag.

I don't want to host my service in IIS plus as of now I haven't overridden any EndPoints, Behaviours etc in .config file.

I tried with below code in my window service's onstart method

WebServiceHost host = new WebServiceHost(typeof(MyService), new Uri(_serviceUrl));

ServiceAuthorizationBehavior myServiceBehavior = host.Description.Behaviors.Find<ServiceAuthorizationBehavior>();
myServiceBehavior.PrincipalPermissionMode = PrincipalPermissionMode.UseWindowsGroups;


After putting above code I queried ServiceSecurityContext.Current and System.Threading.Thread.CurrentPrincipal  my RESTFul's method but they are showing no sign of return

Restful Wcf Service and Mtom with large xml stream


Hi there,

I created one Restful service that accepts Xml stream as a input.

Now i need to send more than 280 mb of data.

While i upload on client side it gives system outofmemory exception.

How can acheive this task using mtom encdoing on the service side and upload more than 280

mb of data through clinet. Also we need the interoperability between client and server.




Can we expect WCF 4 RESTful service enhancements any time soon?

Does anyone know of any future plans for WCF REST enhancements? I tried using WCF 4 REST, but found that it was coming up short on security and didn't support x-www-form-urlencoded mimeTypes. As a consequence, I was forced to use the WCF Rest Contrib library as it has support for multiple formatters plus custom validation. Unfortunately, it turned out that it does NOT support autogenerated help pages, which was very useful considering there is no equivilient to WSDL that can be used for generating custom interfaces. It would be really helpful if there was an out-of-the-box version of WCF that supported features available in WCF Rest Contrib PLUS autogenerated help pages.

Hash-based Message Authentication Code in WCF 4.0 RESTful service


What is an ideal way of implementing "Hash-based Message Authentication Code" in WCF 4.0 REST, with out putting logic inside each service operation logic?  Can you give me an example of using ServiceAuthenticationManager or some kind of service behavior to accomplish this?


RESTful service call results in status code 409 - why?


My RESTful WCF service has methods to retrieve and update an object.  The retrieval works just fine but the update (or PUT) doesn't.

Here's the service interface and implementation:


    public interface ICandidate
        Common.RestResponse<Person> GetPersonByIndex(string index);

        void UpdatePerson(string id, Person person);
    public class Candidate : ICandidate
        [WebGet(UriTemplate = "/{index}",
                RequestFormat = WebMessageFormat.Json,
                ResponseFormat = WebMessageFormat.Json)]
        public Common.RestResponse GetPersonByIndex(string index)
            Common.RestResponse result = new TWA.Common.RestResponse();

            int Index = 0;
            if (Int32.TryParse(index, out Index)) 
                List list = PersonService.GetPersonList(true, true, true);
                if (list.Count > Index)
                    result.Success = true;
                    result.Count = list.Count;
                    result.Data = list[Index];

How to Deploy WCF service(developed using VS2010) on IIS7.0 as a RESTful Service.


Hi Guys,


I am new to WCF development, and i just developed a WCF service using VS2010 as per my client's urgent requirement. They need a RestFul service , which reads data from an Publishing ShraePoint Library which has anonymous access. Intially i tried using the sharePoint built in restful service (LISTDATA.SVC), but as it looks for authentication, it is failing to provide data.

Coming back to the problem, I have developed the wcf service and its working well on wcfclient. I need to deploy this on IIS7.0 as a restful service.

Any guidence and leads would be helpful. This is a bit urgent too.




Ashish, MOSS Learner

Automatic Format Selection in WCF RESTful service

In .NET framework 4.0, Automatic Format Selection feature is introduced by AutomaticFormatSelectionEnabled property of WebHttpBehavior class. The purpose is to dynamically find out and return the response in appropriate format for a service operation.

Post JSON data to WCF RESTful Service using jQuery

The POST request method is basically designed to post data to a web server for storage. That's why its normally used when submitting a complete form. In this WCF RESTful service tutorial, I'll try to explain how we can post JSON data to a WCF RESTful service using jQuery Ajax call with POST type. We discussed about "POST" HTTP verb in previous WCF tutorials but we didn't use it in our implementation. Purpose of this article is to understand "POST" request with complete implementation for a specific operation.

Error Handling in WCF RESTful Service

WCF possesses the capability to handle errors for RESTful services and return appropriate HTTP status code as well as error details using standard formats like JSON or XML. So, WebFaultException is the class used to return:
1. HTTP status code only, or
2. HTTP status code and user-defined type.

Building an ASP.NET Web Api RESTful service

In this short tutorial I will show how to create quickly a RESTful service by using Visual Studio 2012, ASP.NET Web API and Advanced REST Client.

REST acronym stands for REpresentational State Transfer. In the latest years
REST is emerging as a predominant Web service design model. AS another alternative we have Web Services built around SOAP....

Windows Service Applications Tutorials

You can easily create services by creating an application that is installed as a service. For example, suppose you want to monitor performance counter data and react to threshold values. You could write a Windows Service application that listens to the performance counter data, deploy the application, and begin collecting and analyzing data.

WCF Tip: Using Properties in Service Contracts

you'll notice all of the Service Contracts are implemented with interfaces containing only methods. For the longest time I thought that's all that was supported, until I thought about it a little more. In C# land, properties are simply wrappers around a get method and set method, so why wouldn't we be able to use properties in a service contract? Well the answer is we can.
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