我写了一个简单的WCF
代码。并想要托管它。但是当我运行它时显示出一个异常无法托管我的WCF
HTTP could not register URL http://+:8080/. Your process does not have access rights to this namespace
我有一个类库项目,其中我写了我的WCF
代码。然后我加入App.config
文件和写一些代码
的App.config代码:
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<system.serviceModel>
<services>
<service name="DEMO1.HelloService" behaviorConfiguration="mexBehavior">
<endpoint address="HelloService" binding="basicHttpBinding" contract="DEMO1.IHelloService"></endpoint>
<endpoint address="HelloService" binding="netTcpBinding" contract="DEMO1.IHelloService"></endpoint>
<endpoint address="Mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080"/>
<add baseAddress="net.tcp://localhost:8090"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
这是我的接口
[ServiceContract]
public interface IHelloService
{
[OperationContract]
string GetMessage(string name);
}
,我实现了这个
public class HelloService : IHelloService
{
public string GetMessage(string name)
{
return "Name : " + name;
}
}
然后我加入另一个控制台项目到该解决方案和
class Program
{
static void Main()
{
using(ServiceHost host=new ServiceHost(typeof(DEMO1.HelloService)))
{
try
{
host.Open();
Console.WriteLine("Started");
}catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}
}
我的层次
你能告诉我你的服务运行具有管理员或没有? – Developer 2014-09-04 17:15:57
你是否试过以管理员的身份运行应用程序? – Lawrence 2014-09-04 17:17:47
@Singh:我如何检查它,因为WCF代码是在类库中编写的,当我在浏览器中编写localhost:8080,然后什么都不在,页面显示'无法连接' – 2014-09-04 17:20:56