我用c#控制塔程序想调用一个Webservice服务端(http://xurrency.com/api.wsdl),服务端编码是ISO-8859-1
代码如下:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {            ServiceReference1.xurrencyPortTypeClient a = new ConsoleApplication1.ServiceReference1.xurrencyPortTypeClient();
            string[] strs = a.getCurrencies();
        }
    }
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel >
        <bindings>
            <basicHttpBinding>
                <binding  name="xurrencyBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="6553600" maxBufferPoolSize="524288" maxReceivedMessageSize="6553600"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://xurrency.com/servidor_soap.php" binding="basicHttpBinding"
                bindingConfiguration="xurrencyBinding" contract="ServiceReference1.xurrencyPortType"
                name="xurrencyPort" />
        </client>
    </system.serviceModel>
</configuration>
按如上配置a对象可以生成,但是a.getCurrencies()报错,错误信息为(The content type text/xml; charset=ISO-8859-1 of the response message does not match the content type of the binding (text/xml; charset=utf-8))我把textEncoding="utf-8"改成textEncoding="ISO-8859-1"
a对象都生成不了,错误信息为(The text encoding 'iso-8859-1' used in the text message format is not supported.
Parameter name: encoding)这个到底怎么搞啊?

解决方案 »

  1.   

    'iso-8859-1' 的网名叫“Windows-1252”,所以它不认啦。改为'Windows-1252' 就是你要的那个了。
      

  2.   

    你把textEncoding="utf-8"删除啊,那个存在就破坏了XML的格式了,XML文件不允许出现那样的标签。
      

  3.   

    删除
    textEncoding="utf-8"
      

  4.   

    找到原因了。原因是,.net 3.5以上有个WCF,如果创建的是service reference的话,使用的就是WCF,而WCF只支持三种编码,具体的忘记了,总之没有Latin (ISO-8859-1), 因此在添加reference时一定要添加.net 2.0的web service reference. 问题就解决了。