无法修复WCF的端点未找到异常 [英] Cant fix WCF's endpoint was not found exception

查看:102
本文介绍了无法修复WCF的端点未找到异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在行上收到此错误Channel.GetMessage(new Message())在此函数中:

I get this error on line "Channel.GetMessage(new Message())" In this function:

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:

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:

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:

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:



MessageService:

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

    public void SendMessage()
    {
    }
}





消息:



Message:

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





IContract:



IContract:

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

    [OperationContract]
    void SendMessage();
}

推荐答案

A * .cs文件只是一个文本文件。它没有任何可以被认为是功能代码的东西。文本文件通常被编译成* .dll,但有一些例外。



您需要有一个标记文件,例如* .asmx,它将指向后面的代码。有其他方法可以调用服务,但扩展名永远不会是* .cs。



您可能想了解ASP.NET和MVC编程的基础知识:



初学者教程理解和实现ASP.NET Web API [ ^ ]
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[^]


这篇关于无法修复WCF的端点未找到异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆