【问题标题】:WCF could not find default endpointWCF 找不到默认端点
【发布时间】:2011-04-10 17:15:05
【问题描述】:

我正在使用对 Web 服务的服务引用并创建了它的新实例。我创建了一条消息并尝试将其发送到 Web 服务,但出现此错误:

找不到默认端点 引用合约的元素 'receivePortService.ITwoWayAsyncVoid' 在 ServiceModel 客户端 配置部分。这可能是 因为没有配置文件 为您的应用程序找到了,或者因为 没有与此匹配的端点元素 合同可以在客户端找到 元素。

现在我正在将此应用程序部署到共享点,所以我只有 dll 文件。有没有办法可以在代码中手动设置配置文件中的属性?

receivePortService.TwoWayAsyncVoidClient client = new TaskCompletedHandler.receivePortService.TwoWayAsyncVoidClient();
Message msg = Message.CreateMessage(MessageVersion.Default,"*",XmlTextReader.Create(xmlMessage));
client.BizTalkSubmit(msg);

如何在没有 app.config 的情况下设置端点地址和内容?

【问题讨论】:

    标签: wcf web-services


    【解决方案1】:

    通常,您的 TwoWayAsyncVoidClient 类应该有几个重载的构造函数 - 特别是一个应该将 BindingEndpointAddress 作为其参数。

    所以在代码中,你可以创建例如

    WSDualHttpBinding myBinding = new WSDualHttpBinding();
    EndpointAddress epa = new EndpointAddress(new Uri("http://yourserver:7777/YourService/TheService.svc"));
    
    receivePortService.TwoWayAsyncVoidClient client = new TaskCompletedHandler.receivePortService.TwoWayAsyncVoidClient(myBinding, epa);
    

    WSDualHttpBinding 是双向/双向绑定(我假设您想使用它,基于您的客户端类的名称),您可能还需要设置其他内容,例如回调合约接口和回调地址 - 但我希望该代码至少可以帮助您入门!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-02
      • 1970-01-01
      • 1970-01-01
      • 2010-09-26
      • 2023-02-16
      • 2011-08-31
      • 2013-06-27
      相关资源
      最近更新 更多