我寫了一個簡單的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