implementing REST in WCF
-
Hi, can anyone please tell me how do i implement the following service as a REST service in WCF.I am using .net3.0,VS2005. also please let me know if anything else has to be installed. thanks in advance.
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;namespace DLL1 {
[ServiceContract]
public interface ICalc{
[OperationContract]
int Addn(int a, int b);\[OperationContract\] int Mult(int a, int b); } public class Calculator:ICalc{ public int Addn(int a, int b) { return (a + b); } public int Mult(int a, int b) { return (a \* b); } }
}
-
Hi, can anyone please tell me how do i implement the following service as a REST service in WCF.I am using .net3.0,VS2005. also please let me know if anything else has to be installed. thanks in advance.
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;namespace DLL1 {
[ServiceContract]
public interface ICalc{
[OperationContract]
int Addn(int a, int b);\[OperationContract\] int Mult(int a, int b); } public class Calculator:ICalc{ public int Addn(int a, int b) { return (a + b); } public int Mult(int a, int b) { return (a \* b); } }
}
You would be better off upgrading to .NET 3.5 - it's a whole lot easier (and you can get the Express editions free). Your code would end up like this:
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
namespace DLL1 {
[ServiceContract]
public interface ICalc{
[WebGet]
[OperationContract]
int Addn(int a, int b);
[WebGet]
[OperationContract]
int Mult(int a, int b);
}
}The bits in Bold are the bits you need to add to make this RESTful. BTW - you should also use webHttpBinding.
Deja View - the feeling that you've seen this post before.
-
You would be better off upgrading to .NET 3.5 - it's a whole lot easier (and you can get the Express editions free). Your code would end up like this:
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
namespace DLL1 {
[ServiceContract]
public interface ICalc{
[WebGet]
[OperationContract]
int Addn(int a, int b);
[WebGet]
[OperationContract]
int Mult(int a, int b);
}
}The bits in Bold are the bits you need to add to make this RESTful. BTW - you should also use webHttpBinding.
Deja View - the feeling that you've seen this post before.
-
Well, you've got a lot more work ahead of you then. This[^] article might be of help - you really need to download the WCF technology samples[^] and have a look at them.
Deja View - the feeling that you've seen this post before.