c# - Z39.50 来自服务器的不可读响应

标签 c# visual-studio-2010 z39.50

我正在使用 C#、Visual Studio 2010 和 Zoom.net 创建一个客户端以从 Z39.50 服务器获取数据,但我收到了无法读取的响应。

我注意到响应包含这样的数字 response但是每行的内容在某些地方是不可读的。我想问题只出在用英语以外的语言书写的单词上,而这些特定单词的结果是数字或奇怪的符号。这是一个file与字节数组响应。

此屏幕截图是对我的客户的回复。

enter image description here

这是我的代码:

class Program
{
    static void Main(string[] args)
    {
        try
        {
            using (var con = new Connection("url", port))
            {
                con.DatabaseName = "<name here>";
                con.Syntax = Zoom.Net.RecordSyntax.GRS1;

                var query = "@attr 1=21 @attr 2=3 @attr 3=3 @attr 4=2 " + 
                            "@attr 5=100 @attr 6=1 \"John\""; 
                var results = con.Search(q);

                for (uint i = 0; i < results.Size; i++)
                {
                     string temp = Encoding.UTF8.GetString(results[i].Content);
                }
            }
        }
        catch(Exception exc)
        {
            Console.WriteLine(exc.Message);
            Console.Read();
        }
    }
}

最佳答案

当我将下面的自定义类用于希腊字符 utf8 编码时,问题就解决了。

namespace MARC
{
    public class advancedGreekClass
    {
        protected byte[] inp;
        protected int pos;

        public advancedGreekClass(byte[] data)
        {
            inp = data;
            pos = 0;
        }

        public string GetString()
        {
            var sb = new StringBuilder(1000000);
            ulong ch;
            for (; ; ) {
                ch = read_advancegreek();
                if (ch == 0) break;
                sb.Append((char)ch);
            }
            return sb.ToString();
        }

        private ulong read_advancegreek()
        {
            int byteArraySize = inp.Length - pos;
            ulong x = 0;
            bool shift = false;
            bool tonos = false;
            bool dialitika = false;

            while (byteArraySize > 0)
            {
                if (inp[pos] == 0x9d) //inp[i]
                {
                    tonos = true;
                }
                else if (inp[pos] == 0x9e)
                {
                    dialitika = true;
                }
                else if (inp[pos] == 0x9f)
                {
                    shift = true;
                }
                else
                    break;

                --byteArraySize;
                pos++;
            }

            if (byteArraySize == 0)
            {
                return 0;
            }

            switch (inp[pos])
            {
                case 0x81:
                    if (shift)
                        if (tonos)
                            x = 0x0386;
                        else
                            x = 0x0391;
                    else
                        if (tonos)
                            x = 0x03ac;
                        else
                            x = 0x03b1;
                    break;
                case 0x82:
                    if (shift)
                        x = 0x0392;
                    else
                        x = 0x03b2;

                    break;
                case 0x83:
                    if (shift)
                        x = 0x0393;
                    else
                        x = 0x03b3;
                    break;
                case 0x84:
                    if (shift)
                        x = 0x0394;
                    else
                        x = 0x03b4;
                    break;
                case 0x85:
                    if (shift)
                        if (tonos)
                            x = 0x0388;
                        else
                            x = 0x0395;
                    else
                        if (tonos)
                            x = 0x03ad;
                        else
                            x = 0x03b5;
                    break;
                case 0x86:
                    if (shift)
                        x = 0x0396;
                    else
                        x = 0x03b6;
                    break;
                case 0x87:
                    if (shift)
                        if (tonos)
                            x = 0x0389;
                        else
                            x = 0x0397;
                    else
                        if (tonos)
                            x = 0x03ae;
                        else
                            x = 0x03b7;
                    break;
                case 0x88:
                    if (shift)
                        x = 0x0398;
                    else
                        x = 0x03b8;
                    break;
                case 0x89:
                    if (shift)
                        if (tonos)
                            x = 0x038a;
                        else
                            if (dialitika)
                                x = 0x03aa;
                            else
                                x = 0x0399;
                    else
                        if (tonos)
                            if (dialitika)
                                x = 0x0390;
                            else
                                x = 0x03af;

                        else
                            if (dialitika)
                                x = 0x03ca;
                            else
                                x = 0x03b9;
                    break;
                case 0x8a:
                    if (shift)
                        x = 0x039a;
                    else
                        x = 0x03ba;

                    break;
                case 0x8b:
                    if (shift)
                        x = 0x039b;
                    else
                        x = 0x03bb;
                    break;
                case 0x8c:
                    if (shift)
                        x = 0x039c;
                    else
                        x = 0x03bc;

                    break;
                case 0x8d:
                    if (shift)
                        x = 0x039d;
                    else
                        x = 0x03bd;
                    break;
                case 0x8e:
                    if (shift)
                        x = 0x039e;
                    else
                        x = 0x03be;
                    break;
                case 0x8f:
                    if (shift)
                        if (tonos)
                            x = 0x038c;
                        else
                            x = 0x039f;
                    else
                        if (tonos)
                            x = 0x03cc;
                        else
                            x = 0x03bf;
                    break;
                case 0x90:
                    if (shift)
                        x = 0x03a0;
                    else
                        x = 0x03c0;
                    break;
                case 0x91:
                    if (shift)
                        x = 0x03a1;
                    else
                        x = 0x03c1;
                    break;
                case 0x92:
                    x = 0x03c2;
                    break;
                case 0x93:
                    if (shift)
                        x = 0x03a3;
                    else
                        x = 0x03c3;
                    break;
                case 0x94:
                    if (shift)
                        x = 0x03a4;
                    else
                        x = 0x03c4;
                    break;
                case 0x95:
                    if (shift)
                        if (tonos)
                            x = 0x038e;
                        else
                            if (dialitika)
                                x = 0x03ab;
                            else
                                x = 0x03a5;
                    else
                        if (tonos)
                            if (dialitika)
                                x = 0x03b0;
                            else
                                x = 0x03cd;

                        else
                            if (dialitika)
                                x = 0x03cb;
                            else
                                x = 0x03c5;
                    break;
                case 0x96:
                    if (shift)
                        x = 0x03a6;
                    else
                        x = 0x03c6;
                    break;
                case 0x97:
                    if (shift)
                        x = 0x03a7;
                    else
                        x = 0x03c7;
                    break;
                case 0x98:
                    if (shift)
                        x = 0x03a8;
                    else
                        x = 0x03c8;

                    break;

                case 0x99:
                    if (shift)
                        if (tonos)
                            x = 0x038f;
                        else
                            x = 0x03a9;
                    else
                        if (tonos)
                            x = 0x03ce;
                        else
                            x = 0x03c9;
                    break;
                default:
                    x = inp[pos];
                    break;
            }
            pos++;

            return x;
        }

        //return new ulong();
    }
}

关于c# - Z39.50 来自服务器的不可读响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28324067/

相关文章:

java - 如何用JAVA连接Z39.50和YAZ客户端?

c# - 有没有更好的方法将 DateTime 修剪到特定精度?

c# - Xamarin:播放声音一分钟

c++ - 让 IBO 工作

c# - 程序集引用之间的差异

api - 如何通过 ISBN 从国会图书馆检索 XML/JSON 中的书籍信息

c# - 如何将模型传递给另一个区域的 Controller ?

c# - RowDataBound Gridview 中的错误 : Specified argument was out of the range of valid values.

visual-studio-2010 - 在 VS2010 中将 version=10.0.0.0 替换为 11.0.0.0 进行更改后出现新的构建错误