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

有线索吗?


当前回答

我得到了同样的错误,我尝试了很多事情,但没有工作,然后我注意到我的“合同”在所有项目中都不一样,我改变了合同,因为在解决方案中所有项目都是一样的,然后它起作用了。 这是项目A

<client>
    <endpoint address="https://xxxxxxxx" binding="basicHttpBinding" bindingConfiguration="basic" contract="ServiceReference.IIntegrationService" name="basic" />
</client>

项目B:

<client>
    <endpoint address="xxxxxxxxxxxxx" binding="basicHttpBinding" bindingConfiguration="basic" contract="ServiceReference1.IIntegrationService" name="basic" />
</client>

最后我将两者都更改为:

<client>
    <endpoint address="https://xxxxxxxxxxx" binding="basicHttpBinding" bindingConfiguration="basic" contract="MyServiceReferrence.IIntegrationService" name="basic" />
</client>

其他回答

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

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

还有另一种方法我找到正确的endpointConfigurationName。

如下所示添加endpointConfigurationName

EservicesNew.ServiceClient eservicenew = new EservicesNew.ServiceClient("BasicHttpsBinding_IService");

如下所示找到endpointConfigurationName

添加Web Reference之后,打开配置。Svcinfo文件中生成的参考文件。

找到了两个端点,我使用了正确的端点bindingConfiguration值,即basichttpbinding_iservice

在我的案例中,我已经将app.config重命名为[appname].exe。手动配置。这最终在文件名中添加了一个额外的.config后缀。解决方案是将其重命名为[appname].exe,以消除额外的.config扩展名。

当我在配置文件元素中引用没有全局作用域操作符的契约时,出现了这个错误。

i.e.

<endpoint contract="global::MyNamepsace.IMyContract" .../>

有效,但

<endpoint contract="MyNamepsace.IMyContract" .../>

给出“无法找到引用合同的默认端点元素”错误。

包含MyNamepsace的程序集。IMyContract位于与主应用程序不同的程序集中,因此这可能解释了使用全局作用域解析的必要性。

我发现(以及复制到客户端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" />