简体   繁体   中英

C# WebService endpoint problem

I'm creating a webservice client. And I have the problem - in MainWindow.xaml there is a message: 'Could not find endpoint element with name 'LightsWSSoap' and contract 'LightsWS.LightsWSSoap' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.' In this file I have something like:

xmlns:vm="clr-namespace:LightsClient2.ViewModels"
<Window.DataContext>
    <vm:MainWindowViewModel />
</Window.DataContext>

And in the MainWindowViewModel the constructor of webservice is used:

LightsWSSoap lService = new LightsWSSoapClient("LightsWSSoap");

Where 'LightsWS' is the name of the Service.

There is an app.config file and there are enpoints definitions in it:

    <client>
        <endpoint address="http://xxx/Lights/LightsWS.asmx"
            binding="basicHttpBinding" bindingConfiguration="LightsWSSoap"
            contract="LightsWS.LightsWSSoap" name="LightsWSSoap" />
        <endpoint address="http://xxx/Lights/LightsWS.asmx"
            binding="customBinding" bindingConfiguration="LightsWSSoap12"
            contract="LightsWS.LightsWSSoap" name="LightsWSSoap12" />
    </client>

What is wrong? Any ideas?

You will need to configure your client endpoint in the App.Config file in your WPF application.

If there is not already an App.Config file you can create one by adding a new item to your project and selecting "Application Configuration File".

The contents of App.Config should look something like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <client>
      <endpoint binding="wsHttpBinding" contract="LightsWS.LightsWSSoap" name="LightsWSSoap"  />
    </client>
  </system.serviceModel>
</configuration>

There is a lot more detailed information on MSDN - http://msdn.microsoft.com/en-us/library/ms731745%28VS.90%29.aspx .

You should add app.config file with definition of your endpoint. Usually it is create by Visual Studio. But if you created your ServiceReference in another assembly (for example, is separate dll), then just copy app.config from that assembly to your WpfApplication.

尝试该线程中的思想,尤其是名称空间。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM