2013-07-02 263 views
1

我已經從Windows服務調用Web服務。 Web服務被引用,並且所有編譯都沒有錯誤和警告。當我打電話從Web服務方法我收到這是如下圖所示的錯誤:Web服務客戶端無法找到Web服務的端點

Nie można odnaleźć elementu punktu końcowego o nazwie „WSHttpBinding_IWebService」 i kontrakcie „RemoteServiceLancerto.IWebService」 w sekcji konfiguracji klienta ServiceModel. Może to być spowodowane tym, że nie znaleziono pliku konfiguracji dla używanej aplikacji lub tym, że w elemencie klienta nie znaleziono elementu punktu końcowego pasującego do tej nazwy. 
    w System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName) 
    w System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration) 
    w System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName) 
    w System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address) 
    w System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress) 
    w System.ServiceModel.ConfigurationEndpointTrait`1.CreateSimplexFactory() 
    w System.ServiceModel.ConfigurationEndpointTrait`1.CreateChannelFactory() 
    w System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait) 
    w System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef() 
    w System.ServiceModel.ClientBase`1..ctor(String endpointConfigurationName, String remoteAddress) 
    w CreativiumCounterService.DatabaseSync.getWebService() w d:\Projekty\Liczniki\CreativiumCounterService\DatabaseSync.cs:wiersz 144 
    w CreativiumCounterService.DatabaseSync..ctor() w d:\Projekty\Liczniki\CreativiumCounterService\DatabaseSync.cs:wiersz 30 
    w CreativiumCounterService.DatabaseSync.get_Instance() w d:\Projekty\Liczniki\CreativiumCounterService\DatabaseSync.cs:wiersz 49 
    w CreativiumCounterService.CounterService.syncronizerWorker(Object sender, ElapsedEventArgs e) w d:\Projekty\Liczniki\CreativiumCounterService\CreativiumCounterService.cs:wiersz 0 

您可能希望看到我的客戶(窗口服務)的app.config所以我在下面;

<bindings> 
    <wsHttpBinding> 
    <binding name="WSHttpBinding_IWebService"> 
     <security mode="TransportWithMessageCredential"> 
     <transport clientCredentialType="None" /> 
     <message clientCredentialType="UserName" /> 
     </security> 

    </binding> 
    </wsHttpBinding> 
</bindings> 
<client> 
    <endpoint address="https://domain.domain.com/Service/Service.svc" 
    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IWebService" 
    contract="RemoteServiceLancerto.IWebService" name="WSHttpBinding_IWebService" /> 
</client> 

<behaviors> 
    <serviceBehaviors> 
    <behavior> 
     <serviceMetadata httpGetEnabled="True"/> 
     <serviceDebug includeExceptionDetailInFaults="True"/> 

    </behavior> 
    </serviceBehaviors> 
</behaviors> 

當然,這只是我的配置(網絡服務部分)與改變Web服務地址的一部分。

下面是我的方法來獲取Web服務(這是作爲RSL引用):

public RSL.WebServiceClient getWebService() 
     { 
      PreciousData details = PreciousData.deserialize(); 
      ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(IgnoreCertificateErrorHandler); 
      String ConnectionString = details.getWebServiceConnectionString(); 

      RSL.WebServiceClient client = new RemoteServiceLancerto.WebServiceClient("WSHttpBinding_IWebService", ConnectionString); 

      client.ClientCredentials.UserName.UserName = details.getWebServiceLogin(); 
      client.ClientCredentials.UserName.Password = details.getWebServicePassword(); 


client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; 
      return client; 
     } 

目前,我在IgnoreCertificateErrorHandler沒有證書驗證,但我告訴它下面:

public bool IgnoreCertificateErrorHandler(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, 
      System.Security.Cryptography.X509Certificates.X509Chain chain, SslPolicyErrors sslPolicyErrors) 
     { 
      return true; 
     } 

另外,如果我在臨時的WinForms應用程序中引用Web服務,然後使用相同的代碼從Web服務調用方法,那麼它就可以工作。如果需要更多細節,我可以提供。我必須指出,在轉向Web服務之後的麻煩開始之前,Web服務已經過測試。我差點忘了。我從System.Timers.Timer已過的事件調用Web服務。

+0

請提一下錯誤文字? 「Niemożnaodnaleźćelementu punktukońcowegoo nazwie」這是什麼? –

+0

這是「無法找到名稱的終端」 –

回答