简体   繁体   English

“找不到引用合同的默认端点元素”

[英]“Could not find default endpoint element that references contract”

Yes, I know the question is probably a repeat, but bear with me here. 是的,我知道这个问题可能是重复的,但在这里请允许我。 I've tried what I've seen in ALL other questions of the same type and STILL haven't managed to get this working. 我已经尝试了在所有其他相同类型的问题中所看到的内容,但STILL仍无法使该功能正常运行。

I'm working with .Net 4.0 in VS2012 Ultimate. 我正在VS2012 Ultimate中使用.Net 4.0。 I have a class library that's supposed to reference a web service. 我有一个应该引用Web服务的类库。 Going through the usual steps (Add Service Reference > enter service URI > Go > find the available service > give it a name > OK) creates the service reference and adds a system.serviceModel tag in the app.config file of my class library. 完成通常的步骤(添加服务引用>输入服务URI>转到>查找可用的服务>为其命名>确定),将创建服务引用,并在类库的app.config文件中添加system.serviceModel标记。

This class library is currently being referenced by a WinForms app that's passing data to it, to be validated with the returned data from web service. WinForms应用程序当前正在引用该类库,该应用程序将数据传递给该类库,并通过Web服务返回的数据进行验证。 However, upon creation of the service client object... 但是,在创建服务客户端对象时...

SHWS.StaticXMLAPISoapClient wsc =
    new SHWS.StaticXMLAPISoapClient();

...the code crashes with the error noted in the question title, "Could not find default endpoint element that references contract 'SHWS.StaticXMLAPISoap' 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." ...代码崩溃,并出现问题标题“无法在ServiceModel客户端配置部分中找到引用合同'SHWS.StaticXMLAPISoap'的默认终结点元素”中指出的错误。这可能是因为未为您的应用程序找到配置文件,或因为在客户端元素中找不到与该合同匹配的端点元素。”

I have tried EVERYTHING I've found on the net, from copying the [class library name].dll.config file to the output folder of the WinForms app, to copying the system.serviceModel tag from one config file to the other, and still no luck. 我已经尝试了网上发现的所有内容,从将[class library name].dll.config文件复制到WinForms应用程序的输出文件夹,再到将system.serviceModel标记从一个配置文件复制到另一个配置文件,以及仍然没有运气。

I'm literally at my wit's end. 我真是机智了。 Any help would be VERY appreciated, since this is one of the key points of the app I'm working on at the moment. 非常感谢您的帮助,因为这是我目前正在开发的应用程序的重点之一。 Apologies for my ridiculous request, and thanks in advance for your time. 抱歉,我的要求可贵,并在此先感谢您的宝贵时间。

您是否尝试过 相同的system.serviceModel节/设置添加到WinForms app.config文件中?

...You know, this is why I sometimes hate this world of software development. ...您知道,这就是为什么我有时讨厌这个软件开发世界。 I removed the class library config file, moved the serviceModel settings to the WinForms app, and specified the name of the endpoint binding I wanted , and by some stupid miracle, it decided to start working now. 我删除了类库配置文件,将serviceModel设置移至WinForms应用程序,并指定了我想要的终结点绑定的名称 ,并通过一些愚蠢的奇迹决定立即开始工作。

SHWS.StaticXMLAPISoapClient wsc =
    new SHWS.StaticXMLAPISoapClient("StaticXMLAPISoap");

Using that instantiation call instead of the one posted in the question, in addition to adding the system.serviceModel settings to the WinForms app.config file seems to have solved the issue and now I can communicate fine with the webservice. 除了将system.serviceModel设置添加到WinForms app.config文件中之外,使用该实例化调用代替问题中发布的调用似乎已解决了该问题,现在我可以与Webservice进行正常通信了。

Oh well. 那好吧。 Such is the magical world of programmming. 这就是编程的神奇世界。

I still don't know WHY it works like this, so if anyone feels like enlightening me, I'll very much appreciate it. 我仍然不知道为什么它会这样工作,所以如果有人想启发我,我将非常感谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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