C# WebService端点问题

发布于 2024-10-06 11:53:48 字数 1083 浏览 0 评论 0原文

我正在创建一个网络服务客户端。我遇到了问题 - 在 MainWindow.xaml 中有一条消息:“在 ServiceModel 客户端配置部分中找不到名称为“LightsWSSoap”和合同“LightsWS.LightsWSSoap”的端点元素。这可能是因为找不到应用程序的配置文件,或者因为在客户端元素中找不到与此名称匹配的端点元素。 在这个文件中,我有类似的内容:

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

在 MainWindowViewModel 中,使用了 webservice 的构造函数:

LightsWSSoap lService = new LightsWSSoapClient("LightsWSSoap");

其中“LightsWS”是服务的名称。

有一个 app.config 文件,其中有 enpoints 定义:

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

出了什么问题?有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

徒留西风 2024-10-13 11:53:48

您需要在 WPF 应用程序的 App.Config 文件中配置客户端端点。

如果还没有 App.Config 文件,您可以通过向项目添加新项目并选择“应用程序配置文件”来创建一个文件。

App.Config 的内容应如下所示:

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

MSDN 上有很多更详细的信息 - http://msdn.microsoft.com/en-us/library/ms731745%28VS.90%29.aspx

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.

没企图 2024-10-13 11:53:48

您应该添加包含端点定义的 app.config 文件。通常它是由 Visual Studio 创建的。但是,如果您在另一个程序集中创建了 ServiceReference(例如,是单独的 dll),则只需将 app.config 从该程序集复制到您的 WpfApplication 即可。

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.

¢蛋碎的人ぎ生 2024-10-13 11:53:48

尝试此线程中的想法,尤其是命名空间。

Try the ideas in this thread, especially the namespaces.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文