VS.NET服务中的非ascii字符 [英] Non-ascii characters in VS.NET service

查看:80
本文介绍了VS.NET服务中的非ascii字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用VS.NET 2003创建了一个简单的.NET 1.1 Web服务:它有一个

方法,它接受一个字符串参数。它遍历输入字符串,

将每个字符转换为十六进制并将其附加到输出字符串,

返回结果。


我现在在

字段中发送包含非ASCII字符的此服务SOAP消息,该字段将成为输入字符串。每个SOAP消息都有一个XML标头

,它正确描述了非ASCII字符的格式。 (我已经b $ b尝试了iso-8859-1和utf-8)。


出于某种原因,每个XML字符都是非-ASCII已变成

问号?在输入字符串中。实际上,一个UTF-8字符

包含两个字节就成了两个问号。这发生在任何我的代码(或任何代码VS.NET愿意向我展示)运行之前,所以我不知道

知道如何调查一下。在尝试使用

来表示不包含它的字符集中的字符时,通常会生成问号,但在

这种情况​​下,目标是C#字符串,这可以代表任何Unicode

字符。


我将不胜感激任何见解。

I''ve created a simple .NET 1.1 web service using VS.NET 2003: it has one
method that takes a string parameter. It iterates through the input string,
turning each character into hex and appending it to an output string, and
returns the result.

I now send this service SOAP messages containing non-ASCII characters in the
field that becomes the input string. Each SOAP message has an XML header
that correctly describes the format of the non-ASCII characters. (I''ve
tried both iso-8859-1 and utf-8).

For some reason, each XML character that''s non-ASCII has been turned into a
question mark "?" in the input string. Actually, a UTF-8 character that
contains two bytes becomes two question marks. This happens before any of
my code (or any code VS.NET is willing to show me) runs, so I''m at a loss to
know how to investigate it. Question marks are often generated when trying
to represent a character in a character set that doesn''t contain it, but in
this case the target is a C# string, which can represent any Unicode
character.

I''d appreciate any insights about this.

推荐答案

Mike Schilling< ms ************* @ hotmail.comwrote:
Mike Schilling <ms*************@hotmail.comwrote:

我''使用VS.NET 2003创建了一个简单的.NET 1.1 Web服务:它有一个

方法,它接受一个字符串参数。它遍历输入字符串,

将每个字符转换为十六进制并将其附加到输出字符串,并且

返回结果。
I''ve created a simple .NET 1.1 web service using VS.NET 2003: it has one
method that takes a string parameter. It iterates through the input string,
turning each character into hex and appending it to an output string, and
returns the result.



如何将字符转换为十六进制?

How is it turning the character into hex?


我现在发送此服务包含非服务的SOAP消息

字段中的-ASCII字符,成为输入字符串。每个SOAP消息都有一个XML标头

,它正确描述了非ASCII字符的格式。 (我已经b $ b尝试了iso-8859-1和utf-8)。
I now send this service SOAP messages containing non-ASCII characters in the
field that becomes the input string. Each SOAP message has an XML header
that correctly describes the format of the non-ASCII characters. (I''ve
tried both iso-8859-1 and utf-8).



XML标题是什么意思?它应该只是在XML

delcaration中。

What do you mean by "an XML header"? It should just be in the XML
delcaration.


由于某种原因,每个非ASCII的XML字符都已被转换进入

问号?在输入字符串中。实际上,一个UTF-8字符

包含两个字节就成了两个问号。
For some reason, each XML character that''s non-ASCII has been turned into a
question mark "?" in the input string. Actually, a UTF-8 character that
contains two bytes becomes two question marks.



这表明无论生成XML文件是什么错误,*或*

您正在查看XML在不合适的编辑器中。你是怎么看
看看XML?


-

Jon Skeet - < sk *** @ pobox。 com>
http://www.pobox.com/~skeet博客: http://www.msmvps.com/jon.skeet

如果回复小组,请不要给我发邮件

That suggests that whatever''s producing the XML file is wrong, *or*
that you''re looking at the XML in an inappropriate editor. How are you
looking at the XML?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too




" Jon Skeet [C#MVP ]" < sk *** @ pobox.com写了留言

新闻:MP ************************ @ msnews。 microsoft.c om ...

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP************************@msnews.microsoft.c om...

Mike Schilling< ms ************* @ hotmail.comwrote:
Mike Schilling <ms*************@hotmail.comwrote:

>我使用VS.NET 2003创建了一个简单的.NET 1.1 Web服务:它有一个采用字符串参数的方法。它遍历输入字符串,
将每个字符转换为十六进制并将其附加到输出字符串,然后返回结果。
>I''ve created a simple .NET 1.1 web service using VS.NET 2003: it has one
method that takes a string parameter. It iterates through the input
string,
turning each character into hex and appending it to an output string, and
returns the result.



如何将角色变成十六进制?


How is it turning the character into hex?



ret + =" 0x" +((int)s [i])。ToString(" X");

ret += "0x" + ((int)s[i]).ToString("X");


>
>

>我现在发送此服务包含非ASCII字符的SOAP消息在
字段中成为输入字符串。每个SOAP消息都有一个XML标头
,它正确描述了非ASCII字符的格式。 (我已经尝试过iso-8859-1和utf-8)。
>I now send this service SOAP messages containing non-ASCII characters in
the
field that becomes the input string. Each SOAP message has an XML header
that correctly describes the format of the non-ASCII characters. (I''ve
tried both iso-8859-1 and utf-8).



XML标题是什么意思?它应该只是在XML

级别中。


What do you mean by "an XML header"? It should just be in the XML
delcaration.



完全正确。每个SOAP消息在其XML

声明中指定正确的编码,如下所示。

Exactly. Each SOAP message specifies the correct encoding in its XML
declaration, as shown below.


>
>

>由于某种原因,每个非ASCII字符的XML字符都变成了
一个问号? "在输入字符串中。实际上,一个包含两个字节的UTF-8字符就成了两个问号。
>For some reason, each XML character that''s non-ASCII has been turned into
a
question mark "?" in the input string. Actually, a UTF-8 character that
contains two bytes becomes two question marks.



这表明无论生成XML文件是什么错误,*或*

您正在查看XML在不合适的编辑器中。你是如何看待XML的?b $ b?


That suggests that whatever''s producing the XML file is wrong, *or*
that you''re looking at the XML in an inappropriate editor. How are you
looking at the XML?



<?xml version =" 1.0" encoding =" iso-8859-1"?>

< soap:Envelope xmlns:xsi =" http://www.w3.org/2001/XMLSchema-instance"

xmlns:xsd ="

http://www.w3.org/2001/XMLSchema"

xmlns:soap =" http: //schemas.xmlsoap.org/soap/envelope/">

< soap:Body>

< ToHex xmlns =" http:// tempuri .org /">

< s>aéì?f< / s>

< / ToHex>

< / soap:Body>

< / soap:Envelope>


NNTP可能会乱码非ASCII字符,但是以十六进制表示字符串

里面< stags是


141 351 354 346 146


使用od -b验证。


在iso-8859-1中,这些分别是


a,e带有重音,我带有重音,ae,f

我可以在本地解析同一个文件,并观察它是正确的(例如,使用下面的程序获得
)。它仅在网上处理时表现奇怪

服务。


使用System;

使用System.Xml;


命名空间XMLParser

{

class ParseXML

{

static void Main (string [] args)

{

XmlDocument doc = new XmlDocument();

doc.Load(" c:\\\ \\ java \\toHex.xml");

dumpStrings(doc);

Console.WriteLine("< Done>");

}


private static void dumpStrings(XmlNode node)

{

if(node is XmlCharacterData)< br $>
{

Console.Out.WriteLine(node.Value);

}

其他

{

for(XmlNode child = node.FirstChild;

child!= null;

child = child.NextSibling)

{

dumpStrings(child);

}

}

}

}

}

<?xml version="1.0" encoding="iso-8859-1"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ToHex xmlns="http://tempuri.org/">
<s>aéì?f</s>
</ToHex>
</soap:Body>
</soap:Envelope>

NNTP is likely to garble the non-ASCII characters, but in hex the string
inside the <stags is

141 351 354 346 146

verified by using od -b.

In iso-8859-1, these are respectively

a, e with an acute accent, i with a grave accent, ae, f

And I can parse the same file locally and observe that it''s correct (e.g.
with the program below). It only acts oddly when processed by the web
service.

using System;
using System.Xml;

namespace XMLParser
{
class ParseXML
{
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load("c:\\java\\toHex.xml");
dumpStrings(doc);
Console.WriteLine("<Done>");
}

private static void dumpStrings(XmlNode node)
{
if (node is XmlCharacterData)
{
Console.Out.WriteLine(node.Value);
}
else
{
for (XmlNode child = node.FirstChild;
child != null;
child = child.NextSibling)
{
dumpStrings(child);
}
}
}
}
}


Mike Schilling< ap @ new sgroup.nospamwrote:


< snip>
Mike Schilling <ap@newsgroup.nospamwrote:

<snip>

我可以在本地解析同一个文件并观察它''是正确的(例如

与下面的程序)。只有在网站处理时才会出现奇怪的行为。

服务。
And I can parse the same file locally and observe that it''s correct (e.g.
with the program below). It only acts oddly when processed by the web
service.



这很奇怪:(


我之前在网络服务中传递了非ASCII字符没有

问题...这很奇怪。


你有一个只有一个网络服务和一个测试应用程序的解决方案

我可以查看一下吗?


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet

如果回复小组,请不要给我发邮件

That''s pretty odd :(

I''ve passed non-ASCII characters in web services before with no
problems... this is very odd.

Do you have a solution with just a web service and just a test app that
I could have a look at?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


这篇关于VS.NET服务中的非ascii字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆