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

有线索吗?


当前回答

当你在类文件中引用服务时,这里有几个响应可以找到正确的解决方案:将服务配置信息复制到app.config web中。这些答案似乎都没有告诉你应该复制什么。让我们试着纠正一下。

下面是我从我的类库的配置文件复制到我的控制台应用程序的配置文件中,为了解决这个疯狂的错误,我写了一个名为“TranslationServiceOutbound”的服务。

你基本上想要系统内的一切。serviceModel部分:

  <system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_ITranslationServiceOutbound" />
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://MyHostName/TranslationServiceOutbound/TranslationServiceOutbound.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITranslationServiceOutbound"
    contract="TranslationService.ITranslationServiceOutbound" name="BasicHttpBinding_ITranslationServiceOutbound" />
</client>

其他回答

我通过自己创建绑定和端点地址实例解决了这个问题(我认为其他人可能已经建议了)——因为我不想向配置文件添加新的设置(这是对一些广泛使用的现有库代码的替换,以前使用的是旧的Web Service Reference等),所以我希望能够在不添加新的配置设置的情况下将其放入。

var remoteAddress = new System.ServiceModel.EndpointAddress(_webServiceUrl);

using (var productService = new ProductClient(new System.ServiceModel.BasicHttpBinding(), remoteAddress))
{
    //set timeout
    productService.Endpoint.Binding.SendTimeout = new TimeSpan(0,0,0,_webServiceTimeout);

    //call web service method
    productResponse = productService.GetProducts();
} 

Edit

如果你正在使用https,那么你需要使用BasicHttpBinding而不是BasicHttpBinding。

在我的情况下,我在启动项目和使用同名服务的项目中都添加了服务。它工作…

我遇到了同样的问题,但是更改契约名称空间对我不起作用。所以我尝试了。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

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