wcf - “Could not find default endpoint element that references contract”

标签 wcf error-handling endpoint

在卸载 Windows 应用程序期间调用 webservice 时出现错误

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

我正在使用调用 Web 服务客户端的 Installer 类。以下是installer.cs的代码

源代码:

namespace webMiner 
{
    [RunInstaller(true)]
    public partial class demoInstaller : Installer
    {
    SqlConnection conn = new SqlConnection("Data Source=servername;Initial Catalog=comp;User Id=abc;Password=******;");

    public demoInstaller():base()
    {

        InitializeComponent();

         AfterUninstall += new InstallEventHandler(AfterUninstallEventHandler);

    }


    public override void Uninstall(System.Collections.IDictionary savedState)
    {
        base.Uninstall(savedState);
        Int32 flag = -1;
        string keyName = "";

            RegistryKey regeditkey = Registry.CurrentUser.OpenSubKey("sevenuser", RegistryKeyPermissionCheck.ReadWriteSubTree);
        keyName = regeditkey.GetValue("currentuser").ToString();

            webMiner.ServiceReference2.Service1Client sc = new webMiner.ServiceReference2.Service1Client();

            flag = sc.unInstallOperation(keyName);


    }

}

其中 unInstallOperation() 将调用包含帐户更新的网络服务操作。

如何解决这个问题? 真的对这个问题感到厌烦

当我从另一个页面或另一个类文件调用 serviceclient 时我没有问题,当我在卸载应用程序期间调用时给我带来问题,即在 Installer 类中。这是我用过的app.config客户端配置代码

源代码:

  <client> 

  <endpoint address="http://companyfind.info/RegWcfService/Service1.svc" 
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
      contract="IService1" name="BasicHttpBinding_IService1" />

   </client>

是否需要在web服务的web.config文件中添加这个??

最佳答案

在实例化 Service1Client 时,您可能需要使用端点的名称

var sc = new webMiner.ServiceReference2.Service1Client("BasicHttpBinding_IService1");

或者,就像我的情况一样,您在解决方案的另一个项目中有另一个类和两个 app.config 类。因此,您需要在主 app.config 中复制/粘贴 enpoints 和绑定(bind)的说明。

关于wcf - “Could not find default endpoint element that references contract”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6955619/

相关文章:

c# - WCF/LINQ to SQL 中的序列化

c# - 自定义绑定(bind) : The provided URI scheme 'https' is invalid; expected 'http' . 参数名称:via

c# - .NET Web 服务 - 如何返回错误?

soap - WSDL 绑定(bind) -soapAction 值

wcf - 数据协定中的 IsReference 属性

c# - 在 WCF (C#) 中引用服务时出现问题

c++ - 使用 cin 检查用户整数输入会产生无限循环

javascript - 如何在浏览器控制台中禁用Javascript错误消息?

azure - 如何使用 Azure CLI 获取与事件中心兼容的终结点连接字符串

java - 是否可以覆盖 Tomcat 中默认的连接器类实现?