1

我从 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 elapsed 事件调用 Web 服务。

4

1 回答 1

1

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

于 2013-07-02T10:59:20.570 回答