找不到默认端点元素

发布于 2024-07-09 16:29:08 字数 720 浏览 13 评论 0原文

我已将代理添加到 VS2008/.NET 3.5 解决方案的 Web 服务。 构造客户端 .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(我提到这一点是因为许多 Google 搜索都提到了 win2k3) app.config 被复制到 app.exe.config,所以这也不是问题。

有什么线索吗?

I've added a proxy to a webservice to a VS2008/.NET 3.5 solution. When constructing the client .NET throws this error:

Could not find default endpoint element that references contract 'IMySOAPWebService' in the ServiceModel client configuration section. This might be because no configuaration file was found for your application or because no endpoint element matching this contract could be found in the client element.

Searching for this error tells me to use the full namespace in the contract. Here's my app.config with full namespace:

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

I'm running XP local (I mention this because a number of Google hits mention win2k3)
The app.config is copied to app.exe.config, so that is also not the problem.

Any clues?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

假扮的天使 2024-07-16 16:29:08

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

在这种情况下,您需要将 WS 配置设置包含到主项目 app.config(如果是 winapp)或 web.config(如果是 Web 应用程序)。 即使使用 PRISM 和 WPF/Silverlight,这也是可行的方法。

"This error can arise if you are calling the service in a class library and calling the class library from another project."

In this case you will need to include the WS configuration settings into the main projects app.config if its a winapp or web.config if its a web app. This is the way to go even with PRISM and WPF/Silverlight.

℡寂寞咖啡 2024-07-16 16:29:08

我通过自己创建绑定和端点地址实例解决了这个问题(我认为正如其他人可能建议的那样) - 因为我不想向配置文件添加新设置(这是广泛使用的一些现有库代码的替代品,并且之前使用过较旧的 Web 服务参考等),因此我希望能够将其放入,而无需在各处添加新的配置设置。

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();
} 

编辑

如果您使用的是 https,则需要使用 BasicHttpsBinding 而不是 BasicHttpBinding

I solved this (I think as others may have suggested) by creating the binding and endpoint address instances myself - because I did not want to add new settings to the config files (this is a replacement for some existing library code which is used widely, and previously used an older Web Service Reference etc.), and so I wanted to be able to drop this in without having add new config settings everywhere.

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

If you are using https then you need to use BasicHttpsBinding rather than BasicHttpBinding.

拍不死你 2024-07-16 16:29:08

测试了几个选项后,我终于通过使用解决了这个问题

契约=“IMySOAPWebService”

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

Having tested several options, I finally solved this by using

contract="IMySOAPWebService"

i.e. without the full namespace in the config. For some reason the full name didn't resolve properly

∞琼窗梦回ˉ 2024-07-16 16:29:08

我也遇到过同样的问题。 事实证明,对于 Web REFERENCE,您必须提供 URL 作为构造函数的第一个参数:

new WebService.WebServiceSoapClient("http://myservice.com/moo.aspx");

对于新样式的 Web SERVICE REFERENCE,您必须提供一个引用配置中端点条目的名称

new WebService.WebServiceSoapClient("WebServiceEndpoint");

Web.configApp.config 中的条目:

<client>
      <endpoint address="http://myservice.com/moo.aspx"
        binding="basicHttpBinding" 
        bindingConfiguration="WebService"
        contract="WebService.WebServiceSoap"
        name="WebServiceEndpoint" />
    </client>
  </system.serviceModel>

很难消除“它在旧程序中工作”的狭隘视野......

I've had this same issue. It turns out that for a web REFERENCE, you have to supply the URL as the first parameter to the constructor:

new WebService.WebServiceSoapClient("http://myservice.com/moo.aspx");

For a new style web SERVICE REFERENCE, you have to supply a name that refers to an endpoint entry in the configuration:

new WebService.WebServiceSoapClient("WebServiceEndpoint");

With a corresponding entry in Web.config or App.config:

<client>
      <endpoint address="http://myservice.com/moo.aspx"
        binding="basicHttpBinding" 
        bindingConfiguration="WebService"
        contract="WebService.WebServiceSoap"
        name="WebServiceEndpoint" />
    </client>
  </system.serviceModel>

Pretty damn hard to remove the tunnel vision on "it worked in an older program"...

疑心病 2024-07-16 16:29:08

我遇到过这样的情况,我将

  • WCF 服务托管在
  • 主项目
  • “类库”类型的
  • 消费者项目中,该项目具有对 WCF 服务的服务引用主项目从消费者项目中调用方法

现在消费者项目具有所有相关的配置设置我的 app.config 的 标签,它仍然抛出与上面相同的错误。

我所做的就是将相同的标签 添加到我的主项目的 app.config 文件中,最后我们就可以开始了。

就我而言,真正的问题是读取了错误的配置文件。 它引用的是主项目的配置,而不是消费者的 app.config。 我花了两个小时才弄清楚这一点。

I had a situation like this, where i had

  • WCF Service Hosted somewhere
  • Main Project
  • Consumer Project of type 'class Library' which has Service reference to a WCF Service
  • Main project calls methods from consumer project

Now the Consumer project had all the related configuration setting in <system.serviceModel> Tag of my app.config, its was still throwing the same error as the above.

All i did is added the same tag <system.serviceModel> to my main project's app.config file, and finally we were good to go.

The Real problem, as far as in my case was, it was reading the wrong configuration file. Instead of consumer's app.config, it was referring main proj's config. it took me two hours to figure that out.

挖鼻大婶 2024-07-16 16:29:08

<块引用>

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

<块引用>

“在这种情况下,您需要将 WS 配置设置包含到主项目 app.config(如果是 winapp)或 web.config(如果是 Web 应用程序)。即使使用 PRISM 和 WPF/Silverlight,这也是可行的方法”


是的,但如果您无法更改主项目(例如 Orchard CMS),您可以将 WCF 服务配置保留在您的项目中。

您需要使用客户端生成方法创建一个服务助手:

public static class ServiceClientHelper
{
    public static T GetClient<T>(string moduleName) where T : IClientChannel
    {
        var channelType = typeof(T);
        var contractType = channelType.GetInterfaces().First(i => i.Namespace == channelType.Namespace);
        var contractAttribute = contractType.GetCustomAttributes(typeof(ServiceContractAttribute), false).First() as ServiceContractAttribute;

        if (contractAttribute == null)
            throw new Exception("contractAttribute not configured");

        //path to your lib app.config (mark as "Copy Always" in properties)
        var configPath = HostingEnvironment.MapPath(String.Format("~/Modules/{0}/bin/{0}.dll.config", moduleName)); 

        var configuration = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = configPath }, ConfigurationUserLevel.None);
        var serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration);

        if (serviceModelSectionGroup == null)
            throw new Exception("serviceModelSectionGroup not configured");

        var endpoint = serviceModelSectionGroup.Client.Endpoints.OfType<ChannelEndpointElement>().First(e => e.Contract == contractAttribute.ConfigurationName);
        var channelFactory = new ConfigurationChannelFactory<T>(endpoint.Name, configuration, null);
        var client = channelFactory.CreateChannel();
        return client;
    }
}

并使用它:

using (var client = ServiceClientHelper.GetClient<IDefaultNameServiceChannel>(yourLibName)) {
                ... get data from service ...
            }

请参阅

"This error can arise if you are calling the service in a class library and calling the class library from another project."

"In this case you will need to include the WS configuration settings into the main projects app.config if its a winapp or web.config if its a web app. This is the way to go even with PRISM and WPF/Silverlight."

Yes, but if you can't change main project (Orchard CMS for example), you can keep WCF service config in your project.

You need to create a service helper with client generation method:

public static class ServiceClientHelper
{
    public static T GetClient<T>(string moduleName) where T : IClientChannel
    {
        var channelType = typeof(T);
        var contractType = channelType.GetInterfaces().First(i => i.Namespace == channelType.Namespace);
        var contractAttribute = contractType.GetCustomAttributes(typeof(ServiceContractAttribute), false).First() as ServiceContractAttribute;

        if (contractAttribute == null)
            throw new Exception("contractAttribute not configured");

        //path to your lib app.config (mark as "Copy Always" in properties)
        var configPath = HostingEnvironment.MapPath(String.Format("~/Modules/{0}/bin/{0}.dll.config", moduleName)); 

        var configuration = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = configPath }, ConfigurationUserLevel.None);
        var serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration);

        if (serviceModelSectionGroup == null)
            throw new Exception("serviceModelSectionGroup not configured");

        var endpoint = serviceModelSectionGroup.Client.Endpoints.OfType<ChannelEndpointElement>().First(e => e.Contract == contractAttribute.ConfigurationName);
        var channelFactory = new ConfigurationChannelFactory<T>(endpoint.Name, configuration, null);
        var client = channelFactory.CreateChannel();
        return client;
    }
}

and use it:

using (var client = ServiceClientHelper.GetClient<IDefaultNameServiceChannel>(yourLibName)) {
                ... get data from service ...
            }

See details in this article.

郁金香雨 2024-07-16 16:29:08

当您遇到从类文件引用服务的令人麻木的模糊错误时,这里的几个响应找到了正确的解决方案:将服务配置信息复制到控制台或 Windows 应用程序的 app.config web.config 中。 但这些答案似乎都没有告诉你要复制什么。 让我们尝试纠正这一点。

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

您基本上想要 system.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>

Several responses here hit upon the correct solution when you're facing the mind-numbingly obscure error of referencing the service from a class file: copy service config info into your app.config web.config of your console or windows app. None of those answers seem to show you what to copy though. Let's try and correct that.

Here's what I copied out of my class library's config file, into my console app's config file, in order to get around this crazy error for a service I write called "TranslationServiceOutbound".

You basically want everything inside the system.serviceModel section:

  <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>

你是年少的欢喜 2024-07-16 16:29:08

这让我抓狂。

我将 Silverlight 3 Prism (CAB) 与 WCF 结合使用

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

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

事实证明,它在 Shell 的 .xap 文件中查找 ServiceReferences.ClientConfig 文件,而不是在模块的 ServiceReferences.ClientConfig 文件中查找。 我添加了端点并绑定到 Silverlight Shell 应用程序中现有的 ServiceReferences.ClientConfig 文件(它调用它自己的 WCF 服务)。

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

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

MyServiceClient myService = new MyServiceClient();

This one drove me crazy.

I'm using Silverlight 3 Prism (CAB) with WCF

When I call a WCF service in a Prism module, I get the same error:

Could not find default endpoint element that references contract
'IMyService' in the service model client configuaration section. This
might be because no configuaration file was found for your application
or because no end point element matching this contract could be found
in the client element

It turns out that its looking in the Shell's .xap file for a ServiceReferences.ClientConfig file, not in the module's ServiceReferences.ClientConfig file. I added my endpoint and binding to the existing ServiceReferences.ClientConfig file in my Silverlight Shell application (it calls it's own WCF services).

Then I had to rebuild the Shell app to generate the new .xap file for my Web project's ClientBin folder.

Now this line of code finally works:

MyServiceClient myService = new MyServiceClient();
放赐 2024-07-16 16:29:08

我在 ASP.NET 应用程序中遇到此错误,其中 WCF 服务已添加到类库中,该类库作为 bin 文件夹中引用的 .dll 文件添加到 ASP.NET 应用程序中。 要解决该错误,需要将引用 WCF 服务的类库中的 app.config 文件中的配置设置复制到 ASP.NET 站点/应用程序的 web.config 设置中。

I was getting this error within an ASP.NET application where the WCF service had been added to a class library which is being added to the ASP.NET application as a referenced .dll file in the bin folder. To resolve the error, the config settings in the app.config file within the class library referencing the WCF service needed to be copied into the web.config settings for the ASP.NET site/app.

烟花易冷人易散 2024-07-16 16:29:08

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

其他人输入的信息解决了此问题的根本原因。 如果您尝试编写自动化测试用例,并且您正在测试的单元实际上会调用服务接口,则需要将服务引用添加到测试项目中。 这是使用库类型的应用程序的错误类型。 但我没有立即意识到这一点,因为我使用接口的代码不在库中。 但是,当测试实际运行时,它将从测试程序集运行,而不是从被测程序集运行。

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

Unit testing a non-library application that consumes a service can cause this problem.

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.

Adding a service reference to the unit test project resolved my issue.

王权女流氓 2024-07-16 16:29:08

我遇到了同样的问题,但是更改合约名称空间对我来说不起作用。 因此,我尝试了 .Net 2 风格的 Web 参考而不是 .Net 3.5 服务参考。 那行得通。

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

I had the same problem, but changing the contract namespace didn't work for me. So I tried a .Net 2 style web reference instead of a .Net 3.5 service reference. That worked.

To use a Web reference in Visual Studio 2008, click on 'Add Service Reference', then click 'Advanced' when the dialog box appears. In that you will find an option that will let you use a Web reference instead of a Service reference.

玻璃人 2024-07-16 16:29:08

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

I found (as well as copying to the client UI's App.config as I was using a Class Library interface) I had to prefix the name of the binding with the name of the Service Reference (mine is ServiceReference in the below).

e.g.:

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

instead of the default generated:

<endpoint address="http://localhost:4000/ServiceName" binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_ISchedulerService"
      contract="ISchedulerService" 
      name="BasicHttpBinding_ISchedulerService" />
苍白女子 2024-07-16 16:29:08

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

I have a situation which in the Unit test. I copied the app.config file to the unit test project. So the unit test project also contains endpoint information.

你怎么这么可爱啊 2024-07-16 16:29:08

我曾经遇到过这个问题。 因为我还在开发使用WCF服务的接口。 我配置了测试应用程序并继续开发。 然后在开发过程中,我更改了一些服务的名称空间。 所以我在 web.config 中仔细检查了“system.serviceModel -> client -> endpoint -> Contract”以匹配 WCF 类。 那么问题就解决了。

I faced this problem once. It was because i was still developing the interface that uses WCF service. I configured test application and continued development. Then in development, i changed some of the services' namespaces. So i double checked "system.serviceModel -> client -> endpoint -> contract" in web.config to match WCF class. Then problem is solved.

聽兲甴掵 2024-07-16 16:29:08

配置中的命名空间应反映客户端默认命名空间(如项目属性中配置的)之后的命名空间路径的其余部分。 根据您发布的答案,我的猜测是您的客户端配置为位于“Fusion.DataExchange.Workflows”命名空间中。 如果您将客户端代码移动到另一个命名空间,则需要更新配置以匹配剩余的命名空间路径。

The namespace in your config should reflect the rest of the namespace path after your client's default namespace (as configured in the project properties). Based on your posted answer, my guess is that your client is configured to be in the "Fusion.DataExchange.Workflows" namespace. If you moved the client code to another namespace you would need to update the config to match the remaining namespace path.

时光倒影 2024-07-16 16:29:08

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

This error can arise if you are calling the service in a class library and calling the class library from another project.

清风夜微凉 2024-07-16 16:29:08

我有同样的问题。我在类库中使用了 WCF 服务,并从 Windows 应用程序项目中调用类库。但我忘记在 Windows 的配置文件中更改 application 项目与类库的 app.Config 文件的 相同。

解决方案:将外部项目的配置更改为与类库的wcf配置相同。

I Have a same Problem.I'm Used the WCF Service in class library and calling the class library from windows Application project.but I'm Forget Change <system.serviceModel> In Config File of windows application Project same the <system.serviceModel> of Class Library's app.Config file.

solution: change Configuration of outer project same the class library's wcf configuration.

心意如水 2024-07-16 16:29:08

您好,我遇到了同样的问题,但最好的解决方案是让 .NET 来配置您的客户端配置。 当我添加带有 http:/namespace/service.svc?wsdl=wsdl0 查询字符串的服务引用时,我发现它不会在客户端创建配置端点。 但是,当我删除 ?wsdl-wsdl0 并仅使用 url http:/namespace/service.svc 时,它会在客户端配置文件中创建端点配置。 简称“?WSDL=WSDL0”。

Hi I've encountered the same problem but the best solution is to let the .NET to configure your client side configuration. What I discover is this when I add a service reference with a query string of http:/namespace/service.svc?wsdl=wsdl0 it does NOT create a configuration endpoints at the client side. But when I remove the ?wsdl-wsdl0 and only use the url http:/namespace/service.svc, it create the endpoint configuration at the client configuration file. for short remoe the " ?WSDL=WSDL0" .

┼── 2024-07-16 16:29:08

不要将服务客户端声明行作为类字段,
相反,在使用的每个方法中创建实例。
所以问题将会得到解决。 如果您将服务客户端实例创建为类字段,则会发生设计时错误!

Do not put service client declaration line as class field,
instead of this, create instance at each method that used in.
So problem will be fixed. If you create service client instance as class field, then design time error occurs !

倾城°AllureLove 2024-07-16 16:29:08

如果您使用的是使用 PRISM 框架的 WPF 应用程序,那么配置应该存在于您的启动项目中(即您的引导程序所在的项目中)。

In case if you are using WPF application using PRISM framework then configuration should exist in your start up project (i.e. in the project where your bootstrapper resides.)

揽月 2024-07-16 16:29:08

似乎有多种方法可以创建/解决此问题。 对于我来说,我使用的 CRM 产品是用本机代码编写的,并且能够调用我的 .NET dll,但我遇到了需要位于主应用程序/之上的配置信息。 对我来说,CRM 应用程序不是 .NET,因此我最终不得不将其放在我的 machine.config 文件中(不是我想要的位置)。 此外,由于我的公司使用 Websense,由于 407 需要代理身份验证问题,我什至很难添加服务引用,这需要对 machine.cong 进行修改。

代理解决方案:

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

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.

Proxy solution:

To get the WCF Service Reference to work I had to copy the information from the app.config of my DLL to the main application config (but for me that was machine.config). And I also had to copy the endpoint information to that same file. Once I did that it starting working for me.

橘寄 2024-07-16 16:29:08

好的。 我的情况有点不同,但最终我找到了解决方案:
我有一个 Console.EXE -> DLL-> 调用 WS1 -> DLL-> 调用 WS2

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

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

Ok. My case was a little diffrent but finally i have found the fix for it:
I have a Console.EXE -> DLL -> Invoking WS1 -> DLL -> Invoking WS2

I have had both the configurations of the service model of WS1, and WS2 in the Console.EXE.config as recommended. - didnt solve the issue.

But it still didn't work, until i have added the WebReference of WS2 to WS1 also and not only to the DLL that actually creating and invoking the proxy of WS2.

何以心动 2024-07-16 16:29:08

如果您在类库中引用 Web 服务,则必须将 app.config 复制到 Windows 应用程序或控制台应用程序

解决方案:将外部项目的配置更改为与类库的 wcf 配置相同。

为我工作

If you reference the web service in your class library then you have to copy app.config to your windows application or console application

solution: change Configuration of outer project same the class library's wcf configuration.

Worked for me

温暖的光 2024-07-16 16:29:08

我有同样的问题
我正在使用桌面应用程序并使用全球天气 Web 服务,

我删除了服务引用并添加了 Web 引用,问题已解决
谢谢

I had the same Issue
I was using desktop app and using Global Weather Web service

I deleted the service reference and added the web reference and problem solved
Thanks

贪恋 2024-07-16 16:29:08

我的解决方案是从客户端 web.config 中的端点名称属性中删除端点名称
这使得代理

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

只需要一整天的时间就可以完成。
此外,一旦修复到位,合约名称就是错误的,尽管在出现初始错误时合约名称是错误的。
双重然后三次检查合同名称字符串!
属性:伊恩

Solution for me was to remove the endpoint name from the Endpoint Name attribute in client web.config
this allowed the proxy to use

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

only took all day to work out.
Also the contract name was wrong once this fix was in place although it had been wrong when the initial error appear.
Double then triple check for contract name strings people !!
attrib: Ian

ヤ经典坏疍 2024-07-16 16:29:08

请允许我再添加一件事来寻找。 (Tom Haigh的答案已经暗示了这一点,但我想明确一点)

我的web.config 文件定义了以下内容:

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

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

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

LR 正确指出,这需要在正确的位置定义。 对我来说,这意味着我的单元测试项目的 app.config 中有一个,以及主服务项目的 web.config 中有一个。

Allow me to add one more thing to look for. (Tom Haigh's answer already alludes to it, but I want to be explicit)

My web.config file had the following defined:

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

I was already using basicHttpsBinding for one reference, but then I added a new reference which required basicHttpBinding (no s). All I had to do was add that to my protocolMapping as follows:

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

As L.R. correctly points out, this needs to be defined in the right places. For me, that meant one in my Unit Test project's app.config as well as one in the main service project's web.config.

心清如水 2024-07-16 16:29:08

当我在没有全局作用域运算符的情况下引用配置文件元素中的 Contract 时,出现此错误。

ie

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

可以工作,但

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

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

包含 MyNamepsace.IMyContract 的程序集与主应用程序位于不同的程序集中,因此这可能解释了需要使用全局范围解析的原因。

I had this error when I was referencing the Contract in the configuration file element without the global scope operator.

i.e.

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

works, but

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

gives the "Could not find default endpoint element that references contract" error.

The assembly containing MyNamepsace.IMyContract is in a different assembly to the main application, so this may explain the need to use the global scope resolution.

油饼 2024-07-16 16:29:08

添加服务引用时

在此处输入图像描述

注意您输入的命名空间:

< img src="https://i.sstatic.net/rp0PV.png" alt="在此处输入图像描述">

您应该将其附加到界面名称中:

<client>
  <endpoint address="http://192.168.100.87:7001/soap/IMySOAPWebService"
            binding="basicHttpBinding" 
            contract="MyNamespace.IMySOAPWebService" />
</client>

When you are adding a service reference

enter image description here

beware of namespace you are typing in:

enter image description here

You should append it to the name of your interface:

<client>
  <endpoint address="http://192.168.100.87:7001/soap/IMySOAPWebService"
            binding="basicHttpBinding" 
            contract="MyNamespace.IMySOAPWebService" />
</client>
孤君无依 2024-07-16 16:29:08

我遇到了同样的错误,我尝试了很多事情但没有成功,然后我注意到我的“合同”在所有项目中都不相同,我更改了合同,因为解决方案中的所有项目都相同,并且比它有效。
这是项目 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>

I got same error and I have tried many things but didn't work, than I noticed that my "contract" was not same at all projects, I changed the contract as would be same for all projects inside solution and than it worked.
This is project A

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

Project B :

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

Finally I changed for both as :

<client>
    <endpoint address="https://xxxxxxxxxxx" binding="basicHttpBinding" bindingConfiguration="basic" contract="MyServiceReferrence.IIntegrationService" name="basic" />
</client>
星軌x 2024-07-16 16:29:08

我遇到了同样的问题,只有当主机应用程序和使用该端点的 dll 具有相同的服务引用名称时,该问题才能得到解决。

I had the same issue and it was solved only when the host application and the dll that used that endpoint had the same service reference name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文