为什么c# Web客户端显示?法语字符



我的web服务客户端返回法语字符的?。我的客户正在调用Apache上的axis2/c web服务。我使用wsdl.exe来生成一个c#代理类。当我在TCPMON中查看返回时,我可以正确地看到法语字符,但在c#中,它们只是显示为?以下是我从TCPMON会话捕获的请求和响应:

------Request ---
POST /axis2/services/Common HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client   Protocol 4.0.30319.18444)
VsDebuggerCausalityData:  uIDPo2iKyNQi9MNOvFI9y0jK6aYAAAAA1bUF2S4JzkGiYsQ0+oayv1AuqfqiggxBj2stf8zH7O4ACQAA
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Host: localhost:9559
Content-Length: 338
Expect: 100-continue
Connection: Keep-Alive
<?xml version="1.0" encoding="utf-8"?><soap:Envelope  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getCriteria  xmlns="http://Common.media.jda.com/service"><userId>2285</userId></getCriteria> </soap:Body></soap:Envelope>
----Response ------------
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Wed, 10 Jun 2015 20:36:41 GMT
Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8e-fips-rhel5   Axis2C/1.6.0
Content-Length: 2052
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/xml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">  <soapenv:Body><n:getCriteriaResponse   xmlns:n="http://Common.media.jda.com/service"><n:getCriteriaReturn>  <n:criteriaId>18219</n:criteriaId><n:criteriaDesc>1415 S   PRIMETIMEá</n:criteriaDesc><n:userId>2285</n:userId> <n:seasonCode>1415</n:seasonCode><n:marketType>S</n:marketType><n:networkCode>P</n:networkCode><n:networkDaypartId>0</n:networkDaypartId><n:salesTypeId>0</n:salesTypeId><n:advId>0</n:advId><n:agencyId>0</n:agencyId><n:acctExecId>0</n:acctExecId><n:plannerId>0</n:plannerId><n:defaultInd>false</n:defaultInd></n:getCriteriaReturn><n:getCriteriaReturn><n:criteriaId>18972</n:criteriaId><n:criteriaDesc>1415 U  Daytimeá</n:criteriaDesc><n:userId>2285</n:userId><n:seasonCode>1415</n:seasonCode><n:marketType>U</n:marketType><n:networkCode>M</n:networkCode><n:networkDaypartId>0</n:networkDaypartId><n:salesTypeId>0</n:salesTypeId><n:advId>0</n:advId><n:agencyId>0</n:agencyId><n:acctExecId>0</n:acctExecId><n:plannerId>0</n:plannerId><n:defaultInd>false</n:defaultInd></n:getCriteriaReturn><n:getCriteriaReturn><n:criteriaId>18221</n:criteriaId><n:criteriaDesc>1415 U PRIMETIMEá</n:criteriaDesc><n:userId>2285</n:userId><n:seasonCode>1415</n:seasonCode><n:marketType>U</n:marketType><n:networkCode>P</n:networkCode><n:networkDaypartId>0</n:networkDaypartId><n:salesTypeId>0</n:salesTypeId><n:advId>0</n:advId><n:agencyId>0</n:agencyId><n:acctExecId>0</n:acctExecId><n:plannerId>0</n:plannerId><n:defaultInd>false</n:defaultInd></n:getCriteriaReturn><n:getCriteriaReturn><n:criteriaId>18284</n:criteriaId><n:criteriaDesc>1516 DADT Upfrontá</n:criteriaDesc><n:userId>2285</n:userId><n:seasonCode>1516</n:seasonCode><n:marketType>U</n:marketType><n:networkCode>I</n:networkCode><n:networkDaypartId>0</n:networkDaypartId><n:salesTypeId>0</n:salesTypeId><n:advId>0</n:advId><n:agencyId>0</n:agencyId><n:acctExecId>0</n:acctExecId><n:plannerId>0</n:plannerId><n:defaultInd>false</n:defaultInd></n:getCriteriaReturn></n:getCriteriaResponse> </soapenv:Body></soapenv:Envelope>

任何帮助都将非常感激。下面是我在wsdl.exe生成的代理类中的函数:

    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestNamespace="http://Common.media.jda.com/service", ResponseNamespace="http://Common.media.jda.com/service", Use=System.Web.Services.Description.SoapBindingUse.Default, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    [return: System.Xml.Serialization.XmlElementAttribute("getCriteriaReturn")]
    public CriteriaRec[] getCriteria(int userId) {
        object[] results = this.Invoke("getCriteria", new object[] {
                    userId});
        return ((CriteriaRec[])(results[0]));
    }

我可以通过创建和覆盖函数来解决这个问题:

protected override WebResponse GetWebResponse(WebRequest request)
{
    WebResponse webResponse = base.GetWebResponse(request);
    webResponse.Headers["Content-Type"] = "text/xml; charset=iso-8859-15";
    return webResponse;
}

这很好。另外,我指定了requestEncoding来处理发回的数据:

myservice.RequestEncoding = System.Text.Encoding.GetEncoding("iso-8859-15");

相关内容

  • 没有找到相关文章

最新更新