1

我有一个具有以下配置的 WCF 服务:

 <service behaviorConfiguration="LoginService.LoginBehavior" name="AuthenticationServices.Login">

        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding"
          bindingConfiguration="WebHttpEndpointBinding"
                  contract="AuthenticationServices.ILoginService">
          <identity>

为了测试该服务,我创建了一个使用它的控制台应用程序。

 static void Main(string[] args)
        {
            LoginService.LoginServiceClient client = new WCFDriver.LoginService.LoginServiceClient();
             client.ValidateUserID();
        }

现在,当我从控制台应用程序调用服务时,它会引发以下错误:

Unhandled Exception: System.InvalidOperationException: The Address property on C
hannelFactory.Endpoint was null.  The ChannelFactory's Endpoint must have a vali
d Address specified.
   at System.ServiceModel.ChannelFactory.CreateEndpointAddress(ServiceEndpoint e
ndpoint)
   at System.ServiceModel.ChannelFactory`1.CreateChannel()
4

1 回答 1

3

您应该为服务或特定端点指定地址(如果有多个端点)。

为服务

<service behaviorConfiguration="LoginService.LoginBehavior" name="AuthenticationServices.Login">

<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding"
      bindingConfiguration="WebHttpEndpointBinding"
              contract="AuthenticationServices.ILoginService"/>
<host>
  <baseAddresses>
    <add baseAddress="http://localhost:5804/SimplePluginService.svc"/>
  </baseAddresses>
</host>

对于端点

<endpoint address="myEndPoint" behaviorConfiguration="web" binding="webHttpBinding"
      bindingConfiguration="WebHttpEndpointBinding"
              contract="AuthenticationServices.ILoginService"/>

端点的地址将添加在基地址之后。

如果您使用 IIS 托管 WCF 服务,则基地址将来自 IIS 的调整,而不是来自<baseAddresses>

于 2012-07-20T13:23:35.467 回答