我已经在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。配置,所以这也不是问题。

有线索吗?


当前回答

请允许我再补充一点。(Tom Haigh的回答已经暗示了这一点,但我想明确一点)

我的网络。配置文件定义如下:

<protocolMapping>
    <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>

我已经使用basicHttpBinding作为一个引用,但随后我添加了一个需要basicHttpBinding的新引用。我所要做的就是将其添加到我的protocolMapping中,如下所示:

<protocolMapping>
    <add binding="basicHttpBinding" scheme="http" />
    <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>

正如L.R.所正确指出的,这需要在正确的地方进行定义。对我来说,这意味着在我的单元测试项目的app.config和主服务项目的web.config中都有一个。

其他回答

我发现(以及复制到客户端UI的App.config,因为我正在使用一个类库接口),我必须以服务引用的名称为绑定的名称前缀(我的是ServiceReference在下面)。

例如:

<endpoint address="http://localhost:4000/ServiceName" binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_ISchedulerService"
      contract="ServiceReference.ISchedulerService" 
      name="BasicHttpBinding_ISchedulerService" />

而不是默认生成:

<endpoint address="http://localhost:4000/ServiceName" binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_ISchedulerService"
      contract="ISchedulerService" 
      name="BasicHttpBinding_ISchedulerService" />

这让我抓狂。

我使用的是带有WCF的Silverlight 3 Prism (CAB)

当我在Prism模块中调用WCF服务时,我得到了相同的错误:

找不到引用合同的默认端点元素 服务模型客户端配置部分中的'IMyService'。这 可能是因为没有找到应用程序的配置文件 或者因为找不到与此契约匹配的端点元素 在client元素中

原来它在Shell的.xap文件中寻找ServiceReferences。ClientConfig文件,而不是模块的ServiceReferences中。ClientConfig文件。我将端点和绑定添加到现有的servicereference中。我的Silverlight Shell应用程序中的ClientConfig文件(它调用它自己的WCF服务)。

然后,我必须重新构建Shell应用程序,为我的Web项目的ClientBin文件夹生成新的.xap文件。

现在这行代码终于可以工作了:

MyServiceClient myService = new MyServiceClient();

嗨,我也遇到过同样的问题,但是最好的解决方案是让. net来配置你的客户端配置。当我使用http:/namespace/service.svc?查询字符串添加服务引用时,我发现了这一点。wsdl=wsdl0,它不会在客户端创建配置端点。但是当我删除wsdl-wsdl0并且只使用url http:/namespace/service时。Svc,它在客户端配置文件中创建端点配置。简而言之,去掉“?WSDL=WSDL0”。

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

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.

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

我遇到了同样的问题,但是更改契约名称空间对我不起作用。所以我尝试了。net 2风格的web引用,而不是。net 3.5的服务引用。这工作。

要在Visual Studio 2008中使用Web引用,请单击“添加服务引用”,然后在出现对话框时单击“高级”。您将发现一个选项,该选项允许您使用Web引用而不是服务引用。