WCF 服务 404 未找到 [英] WCF service 404 Not found

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

问题描述

我有一个基本的 WCF 库项目,我试图将其托管在控制台应用程序中.Program.cs 文件的 Main 方法如下:

I have a basic WCF library project which I am trying to host in console application. The Program.cs file's Main method is as given below:

    static void Main(string[] args)
    {
        // Create a binding and set the security mode to Message.
        BasicHttpBinding b = new BasicHttpBinding();//WSHttpBinding(SecurityMode.Message);

        Type contractType = typeof(SecureWCFLib.IService1);
        Type implementedContract = typeof(SecureWCFLib.Service1);

        Uri baseAddress = new Uri("http://localhost:8733/Design_Time_Addresses/SecureWCFLib/Service1/");

        ServiceHost sh = new ServiceHost(implementedContract, baseAddress);

        sh.AddServiceEndpoint(contractType, b, "Service1");

        ServiceMetadataBehavior sm = new ServiceMetadataBehavior();
        sm.HttpGetEnabled = true;
        sh.Description.Behaviors.Add(sm);

        sh.Open();
        Console.WriteLine("Listening");
        Console.ReadLine();
        sh.Close();


    }

我有另一个作为客户端的控制台应用程序.我正在尝试使用 Program.cs 中的服务,如下所示:

I have another console application which acts as a client. I am trying to consume the service in Program.cs as given below:

 static void Main(string[] args)
        {   
            IService1 productChannel = null;
            EndpointAddress productAddress = new EndpointAddress("http://localhost:8733/Design_Time_Addresses/SecureWCFLib/Service1/");
            productChannel = ChannelFactory<IService1>.CreateChannel(new BasicHttpBinding(), productAddress);
            string result = productChannel.GetData(123);
            Console.WriteLine(result);
            Console.Read();
        }

但我得到异常

{"远程服务器返回错误:(404) 未找到."}

{"The remote server returned an error: (404) Not Found."}

请让我知道我在这里做错了什么.

Please let me know what I am doing wrong over here.

推荐答案

EndpointAddress productAddress = new EndpointAddress("http://localhost:8733/Design_Time_Addresses/SecureWCFLib/Service1/Service1"); 

Services1 添加到构造函数参数的末尾.

add Services1 to the end of constructor parameter.

client endpointaddress = serviceshost_baseAddress + relative address.

您的代码等同于配置:

<service name="SecureWCFLib.Service1">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/SecureWCFLib/Service1/" />
          </baseAddresses>
        </host>
        <endpoint address="Service1" binding="basicHttpBinding" contract="SecureWCFLib.IService1">
        </endpoint>
<behaviors>
<!--......-->
<behaviors>
</service>

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

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