我正在创建一个网络服务客户端。我遇到了问题 - 在 MainWindow.xaml 中有一条消息:“在 ServiceModel 客户端配置部分中找不到名称为“LightsWSSoap”和契约(Contract)“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>
出了什么问题?有什么想法吗?
最佳答案
您需要在 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 .
关于C# WebService端点问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4362295/