コンソール アプリでホストされる BasicHttp および NetTcp バインディング
以下の web.config ファイルがあります
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="HelloService.HelloService" behaviorConfiguration="mexBehaviour">
<endpoint address="HelloService" binding="basicHttpBinding" contract="HelloService.IHelloService"></endpoint>
<endpoint address="HelloService" binding="netTcpBinding" contract="HelloService.IHelloService"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:59084/"/>
<add baseAddress="net.tcp://localhost:59076/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehaviour">
<serviceMetadata httpGetEnabled="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
インターフェイス
namespace HelloService
{
[ServiceContract]
public interface IHelloService
{
[OperationContract]
String GetMessage(String Name);
}
}
インターフェイスを拡張するクラス
using System.ServiceModel;
namespace HelloService
{
public class HelloService : IHelloService
{
public string GetMessage(string Name)
{
return "Hello " + Name;
}
}
}
およびホスティング用のコンソール アプリ コード
using System.ServiceModel;
namespace HelloServiceHost
{
class Program
{
static void Main()
{
using(ServiceHost host = new ServiceHost(typeof(HelloService.HelloService)))
{
host.Open();
Console.WriteLine("Host Started");
Console.ReadLine();
}
}
}
}
コンソール アプリを実行しようとすると、以下のエラーが発生します
HTTP could not register URL http://+:8080/. Your process does not have
access rights to this namespace (see
http://go.microsoft.com/fwlink/?LinkId=70353 for details).
- ポート 8080 が占有されている可能性があると考えて、53895 などの他のポート番号を試しました。運がない!!
このエラーを参照したときに、アカウントが管理者ではないため、この問題を知りました。私の疑問は、WCFTest Client も私のアカウントで実行されていることです。どうすれば同様のコードを実行できますか?
また、この作業を行うための提案は高く評価されます。また Webconfig と何か関係があるのでしょうか??
事前に助けてくれてありがとう!!