2012-07-19 31 views
1

我有以下配置的WCF服務:ChannelFactory.EndPoint上的Address屬性爲null。端點必須有一個有效的地址

<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() 

回答

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>

相關問題