1

尽管有很多关于同一问题的帖子,但我仍然没有弄清楚如何解决有关端点的问题。

在解决方案中有几个项目,在阅读了类似问题后,我通过以下方式编辑了 StartUp Project 的 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.

有谁知道这里可能出了什么问题以及如何解决问题?

4

0 回答 0