Why does C# Web Client display ? for French Characters?

427 views Asked by At

My web service client is returning a ? for French characters. My client is calling an axis2/c web service on Apache. I usedwsdl.exe to generate a c# proxy class. When I look at the return in TCPMON, I can see the French characters correctly but in c# they are just showing up as ?. Here is my request and response captured from TCPMON session:

------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>

Any help would be greatly appreciated. Here is my function in the proxy class generated by 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]));
    }
1

There are 1 answers

0
Shaheed Ahmedi On

I was able to resolve this issue by creating and override function:

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

This works fine. In addition, I specified the requestEncoding to take care of sending data back:

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