【问题标题】:Why does the following code return an error when consuming multiple endpoints of a WCF service?为什么使用 WCF 服务的多个终结点时,以下代码会返回错误?
【发布时间】:2012-04-13 11:06:10
【问题描述】:

我创建了一个多端点 WCF 服务并使用它,它工作正常。

但是当我尝试关闭服务客户端时,出现错误。

这就是我创建客户端对象并为单端点 WCF 服务处理其工作正常的方式

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        ICardPrintingService Service = null;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Service = new CardPrintingServiceClient();
            var response = this.Service.GetCardData(new GetCardDataRequest { NIK = 6666620501740003 });
            try
            {
                ((CardPrintingServiceClient)Service).Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("error");
            }
        }
    }
}

当关闭连接并显示错误消息时,这将进入 catch 块

远程端点不再识别此序列。这是最 可能是由于远程端点上的中止。的价值 wsrm:Identifier 不是已知的序列标识符。可靠的 会话出错。

谁能告诉我为什么?

非常感谢广告

拉格哈文德拉

【问题讨论】:

    标签: wcf c#-4.0


    【解决方案1】:

    这里有什么需要铸造的。

    ((CardPrintingServiceClient)Service).Close(); //pls explain this.
    

    你可以在 finally 块中试试这个。

    if (Service.State != System.ServiceModel.CommunicationState.Closed)
      {
         Service.Abort();
      }
    

    【讨论】:

    • 因为我已经为通过服务公开的接口创建了对象,所以我无法将服务作为 Service.Close 关闭,因此我将把服务类型转换为服务客户端,然后需要关闭并感谢更新会试试的
    • 非常感谢 userGS 这解决了问题,但会在完成诊断后发布统计信息
    猜你喜欢
    • 2019-03-09
    • 2014-01-17
    • 2019-11-29
    • 1970-01-01
    • 1970-01-01
    • 2019-03-13
    • 1970-01-01
    • 2013-05-12
    • 2012-01-16
    相关资源
    最近更新 更多