Click here to Skip to main content
15,885,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I get this error on line "Channel.GetMessage(new Message())" In this function:
C#
public override void Execute()
{
    try
    {
        Behaviours["OntRead"].Do();
        //Ontology = PoolOfBehaviours["OntRead"].SendData();
        Channel.GetMessage(new Message());
    }
    catch
    {
        Console.WriteLine("Ooops");
    }


It belongs to instance of:
XML
public abstract class AbstractAgent
   {
       protected String ID;
       protected BasicHttpBinding Way; 
       protected EndpointAddress EndPoint; 
       protected ChannelFactory<IContract> Links; 
       protected IContract Channel; 
       public Dictionary<String, AbstractBehaviour> PoolOfBehaviours; 

       public Dictionary<String, AbstractBehaviour> Behaviours { get { return PoolOfBehaviours; } } 
       public Uri Adress { get; set; } // где ожидать входящие сообщения
       
       public AbstractAgent(String ID, Uri Adress)
       {
           this.ID = ID;
           PoolOfBehaviours = new Dictionary<string, AbstractBehaviour>();
           this.Adress = Adress;
           EndPoint = new EndpointAddress(Adress);
           Way = new BasicHttpBinding();
           Links = new ChannelFactory<IContract>(Way, EndPoint);
           Channel = Links.CreateChannel();
       }
        public abstract void Execute();
}


I call this function in:
C#
public void Do()
{
    Uri Adress = new Uri("http://localhost/MessageServiceCenter/IContract.cs");
    Post P = new Post(Adress);
    AbstractAgent A = CreateAgent("OntologyF", "OntReader");
    A.AddBehaviour("OntRead", new OntologyLoadBehavior("OntRead", "http://www.semanticweb.org/serega/ontologies/2015/6/SpaceWorld", A));
    P.Open();
    A.Execute();
    P.Close();
}



Post is:
C#
class Post
    {
        public Uri Adress { get; set; }
        private BasicHttpBinding Way;
        private Type Contract;
        private ServiceHost Host;

        public Post(Uri Adress)
        {
            this.Adress = Adress;
            Host = new ServiceHost(typeof(MessageService), Adress);
            Way = new BasicHttpBinding();
            Contract = typeof(IContract);
            Host.AddServiceEndpoint(Contract, Way, "MessageService");
        }

        public void Open()
        {
            Host.Open(); // начало ожидания прихода сообщений
        }

        public void Close()
        {
            Host.Close(); //завершение ожидания прихода сообщений
        }
    }
}


MessageService:
C#
class MessageService : IContract
{
    public void GetMessage(Message Input)
    {
        Input.GOTYA();
    }

    public void SendMessage()
    {
    }
}


Message:
C#
public class Message
{
    public void GOTYA()
    {
        Console.WriteLine("GOTYA");
    }
}


IContract:
C#
[ServiceContract]
public interface IContract
{
    [OperationContract]
    void GetMessage(Message Input);

    [OperationContract]
    void SendMessage();
}
Posted
Comments
F-ES Sitecore 23-Jul-15 4:30am    
WCF is a fairly complex subject, I recommend you get a book on it and work through it. A lot of problems you're going to encounter aren't suitable for forum posts as they will be configuration based. Your code isn't going to work even at a basic level for reasons listed by Andy in Solution 1.

1 solution

A *.cs file is just a text file. It does not have anything that can be considered functional code. The text file is usually compiled into a *.dll with some exceptions.

You need to have a marker file such as *.asmx which will point to the code behind. There are alternative ways to call services but the extension will never be *.cs.

you may like to read up on the basics of ASP.NET and MVC programming:

A Beginner's Tutorial for Understanding and Implementing ASP.NET Web API[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900