Webservice 消费仅在 VS 下调试时有效 IDE

Webservice consuming works only when debugging under VS IDE

我的 WinForms VB.NET 应用程序使用网络服务来执行一些查询。当 运行 在 Visual Studio IDE 下处于调试模式时,它运行顺利,但一旦部署在客户端工作站(甚至在我自己的工作站),它就会崩溃并显示以下消息:

System.InvalidOperationException: Could not find default endpoint element that references contract 'MyServiceReference.IMyService' 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 contract could be found in the client element.

我想在部署中缺少调试时会出现一些东西,但我不知道是什么。

好人S.Dav在上面评论提醒我应该部署app.config和我的.exe文件来解决这个问题。他是对的,如果是答案,我会接受。

此外,我发现我可以硬编码服务配置数据,它也可以工作。

所以我替换了:

Dim myclient as New MyServiceReference.MyServiceClient

来自

Dim myclient as New MyServiceReference.MyServiceClient(
    New BasicHttpBinding(BasicHttpSecurityMode.None),
    New EndpointAddress("http://myservice.mysite.com/services/MyService.svc?wsdl"))

然后 voilà,成功了。

非常感谢所有为此尝试过并提供帮助的人。