我已经在VS2008/中添加了web服务的代理。NET 3.5解决方案。在构造客户端。net时会抛出以下错误:

在ServiceModel客户端配置部分中找不到引用合约“IMySOAPWebService”的默认端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中没有找到与此契约匹配的端点元素。

搜索此错误告诉我在契约中使用完整的名称空间。这是我的app.config完整的命名空间:

<client>
  <endpoint address="http://192.168.100.87:7001/soap/IMySOAPWebService"
            binding="basicHttpBinding" bindingConfiguration="IMySOAPWebServicebinding"
            contract="Fusion.DataExchange.Workflows.IMySOAPWebService" name="IMySOAPWebServicePort" />
</client>

我正在运行XP本地(我提到这是因为一些谷歌点击提到win2k3) 将app.config复制到app.exe。配置,所以这也不是问题。

有线索吗?


当前回答

配置中的名称空间应该反映客户端默认名称空间(如在项目属性中配置的那样)之后的名称空间路径的其余部分。根据你发布的答案,我猜你的客户端被配置为“Fusion.DataExchange”。工作流”名称空间。如果将客户端代码移动到另一个名称空间,则需要更新配置以匹配剩余的名称空间路径。

其他回答

在测试了几个选项之后,我最终通过使用

contract=“IMySOAPWebService”

例如,在配置中没有完整的命名空间。由于某种原因,全名没有正确解析

好的。我的情况有点不同,但最后我找到了解决办法: 我有一个控制台。exe -> DLL ->调用WS1 -> DLL ->调用WS2

我已经按照建议在Console.EXE.config中配置了WS1和WS2的服务模型。没有解决问题。

但它仍然没有工作,直到我将WS2的WebReference也添加到WS1,而不仅仅是添加到实际创建和调用WS2代理的DLL中。

对使用服务的非库应用程序进行单元测试可能会导致此问题。

The information that others have entered addresses the root cause of this. If you are trying to write automated test cases and the unit you are testing will actually invoke the service interface, you need to add the service reference to the test project. This is a flavor of the application using library type of error. I did not immediately realize this though because my code that consumes the interface is not in a library. However, when the test actually runs it will be running from the test assembly, not the assembly under test.

向单元测试项目添加服务引用解决了我的问题。

如果在类库中调用服务,并从另一个项目调用类库,则可能出现此错误。

我有一个情况,在单元测试。我将app.config文件复制到单元测试项目中。因此单元测试项目也包含端点信息。