namespace WcfService1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface HelloWorldService
{
[OperationContract]
[WebGet(UriTemplate = "")]
public string HelloWorld() //here
{
return "Hello world!";
}
}
}
I get this error:
Error 1 The modifier 'public' is not valid for this item
This is what I have in my svc.cs file
public class Service1 : HelloWorldService
{
public string HelloWorld()
{
return string.Format("Hello World!");
}
}
This is actually from a tutorial from my uni:
Unlike last week, where we created interfaces for our services first, we are simply going to create WCF service objects in this first example. This is to save on time within the tutorial. Best practice means that we should be creating interfaces for all our services, which relates to the defined service contract. First of all create a new project within Visual Studio 2008 (remember to add the System.ServiceModel and System.ServiceModel.Web references, and the using declaration for both of these namespaces), and add the following class definition:
[ServiceContract]
public class HelloWorldService
{
[OperationContract]
[WebGet(UriTemplate="")]
public string HelloWorld()
{
return "Hello world!";
}
}
You should be familiar with the basic structure of this WCF service from last week’s tutorial. The difference lies in the extra attribute we have added to the method:
[WebGet(UriTemplate=””)]
This attribute states that the service receives HTTP GET messages (the WebGet part), and that the rest of the URL is not relevant to the service end point (this will become clearer after the later examples). To host this service, we require the following main application:
Members on an
interfacedeclaration can’t have an access modifier. They implicitly have the same accessibility as the containinginterface. If you can access an interface, you can access all it’s members