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

有线索吗?


当前回答

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

其他回答

我通过自己创建绑定和端点地址实例解决了这个问题(我认为其他人可能已经建议了)——因为我不想向配置文件添加新的设置(这是对一些广泛使用的现有库代码的替换,以前使用的是旧的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。

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

There seem to be several ways to create/fix this issue. For me, the CRM product I am using was written in native code and is able to call my .NET dll, but I run into the configuration information needing to be at/above the main application. For me, the CRM application isn't .NET, so I ended up having to put it in my machine.config file (not where I want it). In addition, since my company uses Websense I had a hard time even adding the Service Reference due to a 407 Proxy Authentication Required issue, that to required a modification to the machine.cong.

代理解决方案:

为了让WCF服务引用工作,我必须从我的DLL的app.config复制信息到主应用程序配置(但对我来说是machine.config)。我还必须将端点信息复制到同一个文件中。一旦我这么做了,它就开始为我工作了。

对我来说,解决方案是从客户端web.config中的端点名称属性中删除端点名称 这允许代理使用

ChannelFactory<TService> _channelFactory = new ChannelFactory<TService>("");

锻炼了一整天。 此外,一旦这个修复到位,合同名称是错误的,尽管它在最初的错误出现时是错误的。 再三检查合同名称字符串的人!! 属性:伊恩

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

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

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