WCF 服务创建

Posted

技术标签:

【中文标题】WCF 服务创建【英文标题】:WCF Service Creation 【发布时间】:2011-08-20 17:37:55 【问题描述】:

我正在尝试构建一个小型 WCF 服务并希望在测试应用程序中使用它。

PFB服务代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace HelloIndigo

    [ServiceContract(Namespace="http://www.thatindigoirl.com/samples/2006/06")]
    public interface IHelloIndigoService
    
        [OperationContract]
        string HelloIndigo();
    
    public class HelloIndigoService : IHelloIndigoService
    
        public string HelloIndigo()
        
            return "Hello indigo";
        
    

主机代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace Host

    class Program
    
        static void Main(string[] args)
        
            using (ServiceHost host = new ServiceHost(typeof(HelloIndigo.HelloIndigoService), new Uri("http://localhost:8000/HelloIndigo")))
            
                host.AddServiceEndpoint(typeof(HelloIndigo.IHelloIndigoService), new BasicHttpBinding(), @"HelloIndigoService");
                host.Open();
                Console.WriteLine("Press <ENTER> to terminate the service hosy");
                Console.ReadLine();
            
        
    

每当我尝试运行 Host 时,我都会在 host.Open() 语句中遇到下面提到的错误。

HTTP 无法注册 URL http://+:8000/HelloIndigo/。您的 进程没有访问权限 这个命名空间(见 http://go.microsoft.com/fwlink/?LinkId=70353 详情)。

谁能帮我解决这个问题

【问题讨论】:

如果您发布代码、XML 或数据示例,在文本编辑器中突出显示这些行,然后单击编辑器上的“代码示例”按钮 ( )工具栏以很好地格式化和语法突出显示它! 最重要的部分 - 服务器和客户端的 配置 - 丢失了。没有这些,我们只能猜测..... 您是否点击了错误信息中的微软链接?它解释了它是关于什么的。 【参考方案1】:

您需要以提升的权限(即“作为管理员”)运行主机应用程序。在Vista/Win7下,只有管理员帐号才有注册socket监听的权限。

【讨论】:

@ServiceGuys:非常感谢。它完成了.. 从 XP 切换到 Win7 后我差点忘了这样做 完成.. 对不起,我错过了第一名:)

以上是关于WCF 服务创建的主要内容,如果未能解决你的问题,请参考以下文章

WCF服务二:创建一个简单的WCF服务程序

WCF - WCF基本概念和简单WCF服务端创建

WCF 服务创建

创建 WCF 服务网站

●创建silverlight+wcf

WCF 生成的 wsdl 与为创建 WCF 服务而提供的原始 wsdl 不同?