gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:34:02 25 4
gpt4 key购买 nike

在卸载 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com