在Web服务请求的响应中将ContentType设置两次

时间:2015-03-19 10:25:34

标签: c# web-services magento

尝试通过Web服务访问第三方Magento,但在调用它时会返回错误。如果我的C#处理这个或者这是第三方Web服务的问题,它们的响应似乎包含两个ContentTypes?

The content type application/soap+xml; charset=utf-8,text/xml; charset=UTF-8 of    the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 299 bytes of the response were: '<?xml version="1.0" encoding="UTF-8"?>

使用代码创建绑定;

public static WSHttpBinding CreateBasicBinding(Uri uri)
    {
        TimeSpan timeSpan = new TimeSpan(0, 10, 0);
        WSHttpBinding binding = new WSHttpBinding();

        binding.Name = "Mage_Api_Model_Server_V2_HandlerBinding";
        binding.CloseTimeout = timeSpan;
        binding.OpenTimeout = timeSpan;
        binding.ReceiveTimeout = timeSpan;
        binding.SendTimeout = timeSpan;
        binding.AllowCookies = false;
        binding.BypassProxyOnLocal = false;
        binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
        binding.MaxBufferPoolSize = 524288;
        binding.MaxReceivedMessageSize = 2147483647;
        binding.MessageEncoding = WSMessageEncoding.Text;
        binding.TextEncoding = Encoding.UTF8;
        binding.UseDefaultWebProxy = true;
        binding.ReaderQuotas.MaxDepth = 32;
        binding.ReaderQuotas.MaxStringContentLength = 2147483647;
        binding.ReaderQuotas.MaxArrayLength = 2147483647;
        binding.ReaderQuotas.MaxBytesPerRead = 2147483647;
        binding.ReaderQuotas.MaxNameTableCharCount = 2147483647;

        if (uri.Scheme == Uri.UriSchemeHttps)
        {
            binding.Security.Mode = SecurityMode.Transport;
        }
        else
        {
            binding.Security.Mode = SecurityMode.None;
        }
        binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;
        binding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;
        return binding;
    }

在fidder上查看会将请求标题显示为;

POST /api/v2_soap HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
VsDebuggerCausalityData:                  uIDPo8VmBNS/jbpHhSqfd/IcUJQAAAAAZxIx/YhYK0aeBhguujyyB5Yb7enNZ09At41cx+y2K4wACQAA
Host: www.computerpartsworld.co.uk
Content-Length: 751
Accept-Encoding: gzip, deflate

响应似乎包含两个ContentTypes,是否有任何理由我会返回两个ContentTypes?我无法访问第三方系统,因此无法检查其设置。

HTTP/1.1 200 OK
Date: Thu, 19 Mar 2015 10:21:17 GMT
Server: LiteSpeed
Connection: close
X-Powered-By: PHP/5.4.35
Cache-Control: public, max-age=31536000
Expires: Fri, 18 Mar 2016 10:21:17 GMT
Content-Type: application/soap+xml; charset=utf-8 <---------
Cache-Control: public, max-age=31536000
Expires: Fri, 18 Mar 2016 10:21:17 GMT
Content-Type: text/xml; charset=UTF-8 <---------
Content-Length: 299

0 个答案:

没有答案