0

我创建了一个多端点 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 的值不是已知的序列标识符。可靠会话出现故障。

有人能告诉我为什么吗?

非常感谢广告

拉加文德拉

4

1 回答 1

0

这里有什么需要铸造的。

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

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

if (Service.State != System.ServiceModel.CommunicationState.Closed)
  {
     Service.Abort();
  }
于 2012-04-13T12:52:30.473 回答