我有一个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()
答案 0 :(得分: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>