首页 新闻 会员 周边

WCF 第一章,第一个例子,host open失败,

0
[待解决问题]

看到博主也看了这本书,所以如果有幸,希望博主能指导指导

我第一次学习WCF,参照第一章,第一个实例写了代码,可是host.Open()失败,弄了好久,还是不行,如果博主有空回我一下哦

//新建一个服务

Service.cs

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


namespace HelloIndigo
{
    [ServiceContract(Namespace = "http://www.thatindigogirl.com/samples/2006/06")]
    public interface IHelloIndigoService
    {
        [OperationContract]
        string HelloIndigo();
    }

    public class HelloIndigoService : IHelloIndigoService
    {
        public string HelloIndigo() {
            return "Hello Indigo";
        }
    }
}

 

Host

Program.cs

//创建一个宿主

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

namespace ServiceFromScratch
{
    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 host");
                Console.WriteLine();
            }
        }
    }
}

 

F5运行时,提示跨域访问失败

HTTP could not register URL http://+:8000/HelloIndigo/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details).

wcf
发癫咁学嘢的主页 发癫咁学嘢 | 菜鸟二级 | 园豆:202
提问于:2012-05-11 14:46
< >
分享
所有回答(1)
0

看看你配置文件中的绑定类型是不是wsHttpbinding,如果是,把 host.AddServiceEndpoint(typeof(HelloIndigo.IHelloIndigoService), new BasicHttpBinding(), "HelloIndigoService");中的BasicHttpBinding改成wsHttpbinding,当然也可以把配置文件中的wsHttpbinding改成basicHttpBinding,不过没有wsHttpbinding绑定传输的安全,记住第一个字母要小写。

路遥天 | 园豆:111 (初学一级) | 2012-10-12 10:45
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册