Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt / WSDL / gSOAP = Encoding problems

    3rd Party Software
    3
    7
    4621
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • V
      Virt last edited by

      hi guys,

      I am new to Qt, I need to make a call Web method in my Web service. I started using gSOAP, it works, service calls, but after 2 days of scratching their heads over the encodings.

      Application code:
      @
      QTextCodec::setCodecForCStrings(QTextCodec::codecForName("Windows-1251"));

      CWebService* ws = new CWebService();
      QString Result;
      QString input = "Test, Некая строка";

      if(ws->Test(input, Result))
      {
      //Result = "Server value: Test, Некая строка"
      }
      @

      My test Web method is very simple, it takes a string and returns a modified string, for example: Ship: "test", We get: "Server value: test" When the value "test" comes to the server, Web service sees this value as a "test". The problems start when I send a value: Ship: "Test, Некая строка," We get: "Server value: Test, Некая строка" The application everything is fine, but on the server instead of the "Test, Некая строка" comes the string "Test, Íåêàÿ ñòðîêà"!!! I experimented with all the encoding, I tried to understand how to convert character sets should be turned to this line, and I have not found it.

      Please, Help understand the problem ...

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        Have you tried this:
        @
        if(ws->Test(input.toUtf8(), Result))
        @

        QString stores data as UTF-16, and you probably send that.

        (Z(:^

        1 Reply Last reply Reply Quote 0
        • V
          Virt last edited by

          I try this, but now:
          Web service value = "WS: Test, Некая строка"
          Result = "Server value: Test, Некая строка"

          [quote author="sierdzio" date="1339750726"]Have you tried this:
          @
          if(ws->Test(input.toUtf8(), Result))
          @

          QString stores data as UTF-16, and you probably send that.[/quote]

          1 Reply Last reply Reply Quote 0
          • A
            AcerExtensa last edited by

            Can't you just use UTF-8 on booth sides(server and client)? Why are you messing up with local encoding? Anyway, it seems what your string are sent in windows-1251 encoding but the server thinks/shows string in latin-1 . Take wireshark and look at the client <-> server requests/responses in which language they are talking to each-over and to you.

            One more time for clarify: “Test, Íåêàÿ ñòðîêà” is a ASCII windows-1251 string, represented in ASCII latin-1 charset encoding.

            God is Real unless explicitly declared as Integer.

            1 Reply Last reply Reply Quote 0
            • sierdzio
              sierdzio Moderators last edited by

              Haha, ok, that's not what we call an improvement. Encoding can be really tricky. You have to remember, in your case:

              • you use 1 encoding in your source file
              • this file can be saved using ANOTHER encoding
              • compiler can expect and/ or internally use different encoding from both above
              • you send it over a network, which has it's own encodings...
              • and your web service might be using another one

              Good luck :) Also, I am not sure your use of ::codecForCStrings() is correct, but to be really honest I just don't know how it should look like. Consult the docs.

              (Z(:^

              1 Reply Last reply Reply Quote 0
              • V
                Virt last edited by

                [quote author="AcerExtensa" date="1339751087"]Can't you just use UTF-8 on booth sides(server and client)? Why are you messing up with local encoding? Anyway, it seems what your string are sent in windows-1251 encoding but the server thinks/shows string in latin-1 . Take wireshark and look at the client <-> server requests/responses in which language they are talking to each-over and to you.

                One more time for clarify: “Test, Íåêàÿ ñòðîêà” is a ASCII windows-1251 string, represented in ASCII latin-1 charset encoding. [/quote]

                Yes you are right! I converted the incoming value in the Value parameter of my Web Method .Asmx Web Service and was the original meaning in Russian.

                The Web service code in C #
                @
                [WebMethod]
                public string Test(string Value)
                {
                Value = Encoding.GetEncoding(1251).GetString(Encoding.GetEncoding("Latin1").GetBytes(Value));
                //some code ...
                }
                @

                I must say, my Web service is running in UTF-8 on the request and response. It turns out that the problem in my Qt application, namely, the conversion takes place somewhere in the encoding Latin1 ??? o_O

                1 Reply Last reply Reply Quote 0
                • A
                  AcerExtensa last edited by

                  maybe in gSOAP? look with wireshark into Request Headers from your app.

                  God is Real unless explicitly declared as Integer.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post