托管WCF服务时我得到了例外 [英] When Hosting the WCF service i got exception
问题描述
我收到了这个错误。
System.ServiceModel.dll中发生了'System.ServiceModel.AddressAccessDeniedException'类型的未处理异常
附加信息:HTTP无法注册URL http:// +:7001 / Class1 /。您的进程没有此命名空间的访问权限(请参阅 http://go.microsoft.com/fwlink/?LinkId= 70353 [ ^ ]了解详情)
我在没有WCF模板的情况下使用。我正在创建wcf服务。
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.ServiceModel;
命名空间 ConsoleApplication2
{
[ServiceContract]
interface Interface1
{
[OperationContract]
string getdata();
}
}
< pre lang =cs> 使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.ServiceModel;
命名空间 ConsoleApplication2
{
class Class1: Interface1
{
public string getdata()
{
return wcf;
}
}
}
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.ServiceModel;
命名空间 ConsoleApplication2
{
class Program
{
静态 void Main( string [] args)
{
ServiceHost obj = new ServiceHost( typeof < /跨度>(1类));
obj.AddServiceEndpoint( typeof (Interface1), new BasicHttpBinding(), http:// localhost:7001 / Class1);
obj.Open();
Console.WriteLine( 启动服务);
Console.ReadKey();
}
}
}
我在Open方法程序中遇到错误。
我被推荐更多的网站,但我无法得到答案。
请任何人帮助我。
让Class1公开。
我只更改了。
[ServiceContract]
interface Interface1
{
[OperationContract]
string getdata();
}
public class Class1:Interface1
{
public string getdata()
{
返回 wcf;
}
}
class 计划
{
static void Main( string [] args)
{
ServiceHost obj = new ServiceHost( typeof (Class1));
obj.AddServiceEndpoint( typeof (Interface1), new BasicHttpBinding(), http:// localhost:7001 / Class1);
obj.Open();
Console.WriteLine( 启动服务);
Console.ReadKey();
}
}
工作正常,没有任何错误。
我有同样的错误,但是当我以管理员身份运行我的服务时它会正常工作。
非常感谢你!
打开你的Visual Studio'以管理员身份运行,然后运行您的WCF服务。我希望现在它会运行。
谢谢:)
I got this error.
An unhandled exception of type 'System.ServiceModel.AddressAccessDeniedException' occurred in System.ServiceModel.dll
Additional information: HTTP could not register URL http://+:7001/Class1/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353[^] for details)
I am using without WCF template . i am creating the wcf service.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace ConsoleApplication2
{
[ServiceContract]
interface Interface1
{
[OperationContract]
string getdata();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace ConsoleApplication2
{
class Class1 :Interface1
{
public string getdata()
{
return "wcf";
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
ServiceHost obj = new ServiceHost(typeof(Class1));
obj.AddServiceEndpoint(typeof(Interface1), new BasicHttpBinding(), "http://localhost:7001/Class1");
obj.Open();
Console.WriteLine("start the service");
Console.ReadKey();
}
}
}
I got the error in program of Open methods.
I was referred more sites but i cannot got the answer .
please any one help me.
Make Class1 public.
I have changed only that.
[ServiceContract] interface Interface1 { [OperationContract] string getdata(); } public class Class1 : Interface1 { public string getdata() { return "wcf"; } } class Program { static void Main(string[] args) { ServiceHost obj = new ServiceHost(typeof(Class1)); obj.AddServiceEndpoint(typeof(Interface1), new BasicHttpBinding(), "http://localhost:7001/Class1"); obj.Open(); Console.WriteLine("start the service"); Console.ReadKey(); } }
It worked fine without any error.
I had same error , but when I run my services as administrator then it will work fine.
Thank you so much!
Open your Visual Studio as 'Run As Administrator' and then run your WCF service. I hope Now It will run.
Thanks :)
这篇关于托管WCF服务时我得到了例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!