Web服务客户端无法找到Web服务的端点

时间:2013-07-02 09:07:16

标签: c# windows wcf service web

我已从Windows服务调用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

您可能想要查看我的客户端(Windows服务)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服务地址。

下面是获取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服务。

1 个答案:

答案 0 :(得分:1)

我发现这里提出的解决方案(第二个答案): https://stackoverflow.com//questions/3703844/consume-a-soap-web-service-without-relying-on-the-app-config解决了我的问题,因为我在代码中创建了对象。我希望我能找到答案,为什么它不会读取app.config来自动创建WSHttpBinding