I am trying to start my first WCF service.
Well, I want to note that I completely understood the architecture and columns of WCF (ABC: address binding and contract = endpoint). In addition, I understood many elements of the WCF philosophy, so I'm not just just newbye ...
However, the theory aside, real problems arise when someone puts their hands on real things ...
I have three files:
File IService1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace EchoWcfLibrary {
[ServiceContract]
public interface IService1 {
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
}
[DataContract]
public class CompositeType {
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue {
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue {
get { return stringValue; }
set { stringValue = value; }
}
}
}
File Service1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace EchoWcfLibrary {
public class Service1 : IService1 {
public string GetData(int value) {
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite) {
if (composite == null) {
throw new ArgumentNullException("composite");
}
if (composite.BoolValue) {
composite.StringValue += "Suffix";
}
return composite;
}
}
}
These files are placed inside a project called EchoWcfLibrary
And most importantly: Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using EchoWcfLibrary;
namespace WcfServiceApplication {
public static class Program {
static void Main(string[] args) {
using (ServiceHost host = new ServiceHost(typeof(Service1), new Uri("http://localhost:8080/service1"))) {
host.AddServiceEndpoint(typeof(IService1), new BasicHttpBinding(), "svc");
host.AddServiceEndpoint(typeof(IService1), new NetTcpBinding(), "net.tcp://localhost:8081/service1/tcpsvc");
host.Open();
System.Threading.Thread.Sleep(1000000);
host.Close();
}
}
}
}
This last file is in a separate project called WcfServiceApplication
These two projects exist in one solution.
WcfServiceApplicationhas, of course, a link to another project.
I would like to run this service, which, as you can see, is the one that Visual Studio places in the WCF library template.
, HTTP, netsh http.
: - WCF, , , . : , , , , NO ENDPOINT !!!
Program.cs... ...
?
Thankyou
PS
, host.AddServiceEndpoint(typeof(IService1), new BasicHttpBinding(), "svc") ( tcp) ....
: , ... , , , -, , , ...