Web服务未检测到? [英] Web Service not detected?

查看:203
本文介绍了Web服务未检测到?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,当我在一个不同的视觉工作室运行时打开一个新的项目,并尝试添加一个Web服务就无法找到任何东西举办这个服务,低于该运行正常了吗?而不是在本地计算机上指定的地址或什么?下面只代码似乎当我在同一个解决方案,运行它的工作?

I am trying to host this service below which runs fine yet when I open a new project in a a different visual studio runtime and try to add a web service it cant find anything? Not at the address specified or anything on the local machine? The code below only seems to work when I run it in the same solution?

namespace Students
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create the address for the service
            Uri address = new Uri("http://localhost:8001");
            // Create the binding for the service
            WSHttpBinding binding = new WSHttpBinding();
            // Create the service object
            StudentService service = new StudentService();
            // Create the host for the service
            ServiceHost host = new ServiceHost(service, address);
            // Add the endpoint for the service using the contract, binding and name
            host.AddServiceEndpoint(typeof(IStudentService),
                                    binding,
                                    "students");

            // Open the host
            host.Open();
            Console.WriteLine("Student service started");
            Console.WriteLine("Press return to exit");
            Console.ReadLine();
            // Close the host
            host.Close();
        }
    }


}

我得到的,当我试图把它从一个新的项目(独立于当前的解决方案),添加的错误是这样的:

The error I get when I try to add it from a new project (seperate to the current solution) is this:

The HTML document does not contain Web service discovery information.
Metadata contains a reference that cannot be resolved: 'http://localhost:8001/'.
There was no endpoint listening at http://localhost:8001/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found.
If the service is defined in the current solution, try building the solution and adding the service reference again.



,当我下载了这个案例研究(启动项目),它没有网络或应用程序的配置文件任何地方从控制台应用程序刚刚主办。

Which when I downloaded this case study (starter project) it had no web or app config files anywhere it just hosted from the console apps.

另外请注意我有服务运行时我尝试添加Web服务。

Also note I have the service running when I try to add the web service.

推荐答案

添加元数据交换行为的ServiceHost的。

Add Metadata Exchange behavior in your ServiceHost.

namespace Students
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create the address for the service
            Uri address = new Uri("http://localhost:8001");
            // Create the binding for the service
            WSHttpBinding binding = new WSHttpBinding();
            // Create the service object
            StudentService service = new StudentService();
            // Create the host for the service
            ServiceHost host = new ServiceHost(service, address);
            // Add the endpoint for the service using the contract, binding and name
            host.AddServiceEndpoint(typeof(IStudentService),
                                    binding,
                                    "students");

            // Add metadata exchange
            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            host.Description.Behaviors.Add(smb);

            // Open the host
            host.Open();
            Console.WriteLine("Student service started");
            Console.WriteLine("Press return to exit");
            Console.ReadLine();
            // Close the host
            host.Close();
        }
    }
}

http://wcftutorial.net/WCF-Self-Hosting.aspx

这篇关于Web服务未检测到?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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