同じ問題に関する投稿はたくさんありますが、エンドポイントに関する問題を解決する方法がまだわかりません。
ソリューションにはいくつかのプロジェクトがあり、同様の問題について読んだ後、スタートアッププロジェクトのapp.configファイルを次のように編集しました。
<system.serviceModel>
<services>
...
<service name="LiveGames.Engine.LoginService">
<endpoint address="" name="ILoginService" binding="wsHttpBinding" contract="LiveGames.Entities.Interfaces.ILoginService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/LiveGames.Engine/LoginService/" />
</baseAddresses>
</host>
</service>
</services>
<client>
<endpoint address="http://localhost:8732/LiveGames.Engine/LoginService/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ILoginService" contract="LiveGames.Entities.Interfaces.ILoginService"
name="ILoginService" kind="" endpointConfiguration="">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
次のメソッドを使用してProxyクラスを作成しました。
public ChannelFactory<T> GetFactory<T>(string serviceName, out T channel)
{
ChannelFactory<T> factory = new ChannelFactory<T>(serviceName);
channel = factory.CreateChannel();
return factory;
}
public JSONUserLogin Login(string username, string password)
{
JSONUserLogin retval = new JSONUserLogin();
ILoginService sec = null;
ChannelFactory<ILoginService> factory = null;
try
{
using (factory = GetFactory<ILoginService>("ILoginService", out sec))
{
retval = sec.Login(username, password);
}
return retval;
}
catch (Exception ex)
{
return new JSONUserLogin();
}
finally
{
if (sec != null)
((IChannel)sec).Close();
if (factory != null)
factory.Close();
}
}
serviceName="ILoginService"
実行がラインに到達したときChannelFactory<T> factory = new ChannelFactory<T>(serviceName);
例外をスローします:
System.InvalidOperationException: Could not find endpoint element with name 'ILoginService' and contract 'LiveGames.Entities.Interfaces.ILoginService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.
ここで何が間違っている可能性があり、問題を解決する方法を誰かが知っていますか?