如何绑定端点?

时间:2012-12-22 19:13:49

标签: wcf wcf-binding

虽然有很多关于同一问题的帖子,但我仍然没有想出如何解决有关端点的问题。

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

有谁知道这里可能出现的问题以及如何解决问题?

0 个答案:

没有答案