我在客户端使用javascript调用webservice,传递参数值是个中文,到service得到的却是乱码var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var dom = new ActiveXObject("Microsoft.XMLDOM");
xmlhttp.open("POST","../../WebService/ADRReport.asmx/GetFactoryItems", false);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");xmlhttp.send("pillCurrencyName=复方炔诺酮片&pillMerchandiseName=复方炔诺酮片");
dom.loadXML(xmlhttp.responseText);
....后台service(C#写的)
public string[] GetFactoryItems(string pillCurrencyName,string pillMerchandiseName)
{
string msg;
System.Diagnostics.Trace.WriteLine(pillCurrencyName);
if(!dataSet.FactoryItems(pillCurrencyName,pillMerchandiseName,out msg))这个pillCurrencyName获得的是乱码,怎么解决webconfig里我已经加了
 <globalization requestEncoding="gb2312" responseEncoding="gb2312" 
fileEncoding="gb2312"></globalization>

解决方案 »

  1.   

    跟service没有关系,应该是你用javascript调用方处理编码不正解引起的
      

  2.   

    我在客户端这样写
    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    var dom = new ActiveXObject("Microsoft.XMLDOM");
    xmlhttp.open("POST","../../WebService/ADRReport.asmx/GetFactoryItems", false);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");xmlhttp.send("pillCurrencyName="+encodeURIComponent(复方炔诺酮片)+"&pillMerchandiseName=="+encodeURIComponent(复方炔诺酮片));
    dom.loadXML(xmlhttp.responseText);后台我使用
    pillCurrencyName = HttpUtility.UrlDecode(pillCurrencyName.ToLower());
    还是乱码
      

  3.   

    复方炔诺酮片
    用URLEncode编码一下
      

  4.   

    YAOHE(吆喝) ,应该怎么做?
      

  5.   

    URLEncode,javascript不认这个函数?
      

  6.   

    var urltest = "pillCurrencyNameURLEncode('复方炔诺酮片')+"&pillMerchandiseName="+URLEncode('复方炔诺酮片');
    alert(urltest);
    //xmlhttp.send("pillCurrencyName="+vPillCurrencyName+"&pillMerchandiseName="+vPillMerchandiseName);
    xmlhttp.send(urltest);
    这个直接灸报错,URLEncode不存在
      

  7.   

    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=GB2312'); 不知道这个行不行
      

  8.   

    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=GB2312'); 
    //xmlhttp.setRequestHeader("Content-Type","text/html");
    //xmlhttp.setRequestHeader("Content-Type","charset=gb2312"); alert(vPillCurrencyName);
    alert(vPillMerchandiseName);
    //var urltest = "pillCurrencyName="+vPillCurrencyName+"&pillMerchandiseName="+vPillMerchandiseName;
    var urltest = "pillCurrencyName="+encodeURIComponent(vPillCurrencyName)+"&pillMerchandiseName="+encodeURIComponent(vPillMerchandiseName);
    alert(urltest);
    //xmlhttp.send("pillCurrencyName="+vPillCurrencyName+"&pillMerchandiseName="+vPillMerchandiseName);
    xmlhttp.send(urltest);
    试了还是不行
    在C#获得值仍然是乱码
      

  9.   

    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=GB2312'); 
    var urltest = "pillCurrencyName=复方炔诺酮片&pillMerchandiseName=复方炔诺酮片";
    xmlhttp.send(urltest);
    后台
    public string[] GetFactoryItems(string pillCurrencyName,string pillMerchandiseName)
    {
    System.Diagnostics.Trace.WriteLine(pillCurrencyName);我监测还是乱码
      

  10.   

    你的webservice中的web.config是什么编码设置
      

  11.   

    <?xml version="1.0" encoding="utf-8" ?><globalization requestEncoding="gb2312" responseEncoding="gb2312" 
    fileEncoding="gb2312"></globalization>
      

  12.   

    <?xml version="1.0" encoding="gb2312" ?><globalization requestEncoding="gb2312" responseEncoding="gb2312" 
    fileEncoding="gb2312"></globalization>改成这样也不行
      

  13.   

    那你参看如下的方法是否能解决你的问题
    http://blog.csdn.net/knight94/archive/2006/05/01/704645.aspx
      

  14.   

    Knight94(愚翁)我使用你的函数解码之后仍然是乱码
      

  15.   

    public string GetUnicodeString( string sValue ) { System.Text.Encoding def = System.Text.Encoding.Default; System.Text.Encoding unicode = System.Text.Encoding.UTF8;         // Check whether default encoding is same as "UTF-8" encoding if( def == unicode ) return sValue;  // Check parameter if( sValue == null || sValue.Length == 0 ) return sValue;  // Convert the string into a byte[]. byte[] defBytes = def.GetBytes( sValue );  // Perform the conversion from one encoding to the other. byte[] unicodeBytes = Encoding.Convert( def, unicode, defBytes); char[] uniChars = new char[ unicodeBytes.Length] ; for( int i = 0; i < unicodeBytes.Length; i++ ) uniChars[i] = (char)(unicodeBytes[i]);  return new string( uniChars ); }
    pillCurrencyName = GetUnicodeString(pillCurrencyName);
    得到的仍然是乱码
      

  16.   

    你是说在javascript中使用GetUnicodeString先把中文字符串转换?
    那不是一样吗?还是要穿参数给GetUnicodeString
      

  17.   

    呵呵,解决了,只要这样就可以了xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8'); 
    参数都不需要编码,后台也不需要解码de