2015-02-04 2 views
3

저는 C#, Visual Studio 2010 및 Zoom.net을 사용하여 클라이언트를 만들어 Z39.50 서버에서 데이터를 가져 오지만 읽을 수없는 응답이 나타납니다.Z39.50 서버에서 읽을 수없는 응답

응답에이 response과 같은 숫자가 포함되어 있지만 모든 줄의 내용이 읽을 수없는 곳이 있다는 것을 알게되었습니다. 나는이 문제가 영어 이외의 다른 언어로 쓰여진 단어 들일 뿐이라고 생각하며,이 특정 단어에 대한 결과는 숫자 나 이상한 기호로 나타납니다. 바이트 배열 응답이있는 file입니다.

이 스크린 샷은 내 클라이언트에 대한 응답입니다. 나는 그리스어 문자 UTF8 인코딩 아래의 사용자 정의 클래스를 사용 whed

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(); 
     } 
    } 
} 
+0

이 코드를 실행할 때 궁금한 점이 있습니까? 그렇다면 코드에서 오류가 발생/생성되는 줄을 설명하십시오. [C# Zoom.Net] (http://jai-on-asp.blogspot.com/2010/01/z3950-client) -in-cnet-using-zoomnet-and.html) – MethodMan

+0

'연결'은 어떤 라이브러리에서 왔습니까? 설명서에서 사용법에 대해 무엇을 말하고 있습니까? 응답이 UTF-8이라고 확신합니까? 어떤 형식으로 응답을 기대하십니까? – CodeCaster

+1

이것은 내가 들어가는 회선이며이 응답을보고 있습니다. string temp = Encoding.UTF8.GetString (results [i] .Content); 연결이 제공되는 라이브러리는 Zoom.Net입니다. – Apostolos

답변

2

문제 해결 :

enter image description here

여기 내 코드입니다.

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(); 
    } 
} 
관련 문제