Attempt to start the first WCF service

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;

/// <summary>
/// This is the interface that specifies contract for the Sevice1 of this service application.
/// In this file the interface is specified in order to set the service operations that can be invoked by requestors.
/// </summary>
namespace EchoWcfLibrary {
    /// <summary>
    /// The interface specifies for those classes implementing it (services), the operation that the service will expose.
    /// </summary>
    [ServiceContract]
    public interface IService1 {
        // This does not use serialization (implicit serialization in considered: base types used).
        [OperationContract]
        string GetData(int value);
        // This uses data contracts and serialization.
        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);
    }

    /// <summary>
    /// The following class defines data contract for those operations managing with non primitive types and, for this reason, needing serialization support (explicit, not implicit)
    /// </summary>
    [DataContract]
    public class CompositeType {
        // Members not serialized
        bool boolValue = true;
        string stringValue = "Hello ";
        // Serialized
        [DataMember]
        public bool BoolValue {
            get { return boolValue; }
            set { boolValue = value; }
        }
        // Serialized
        [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;

/// <summary>
/// This is the service host implementation. A class implementing the service is specified.
/// </summary>
namespace EchoWcfLibrary {
    /// <summary>
    /// This class implements the IService1 service.
    /// </summary>
    public class Service1 : IService1 {
        // One operation.
        public string GetData(int value) {
            return string.Format("You entered: {0}", value);
        }
        // The other operation.
        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) {
            // Setting endpoints and setting the service to start properly.
            // Base address specified: http://localhost:8080/service1
            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) ....

: , ... , , , -, , , ...

+3
1

, : "svc" (http) "net.tcp://localhost: 8081/service1/tcpsvc" (tcp), , , .

, , .config , WCF Service, Visual Studio ( 2008 ), .

+4

All Articles