开发者

Disable gzip compression in request to GeoCoder web site

I have a example application written in Delphi using /N Software's SOAP component. This application communicates with the GeoCoder site (see geocoder.us) to get latitude and longitude from a provided address. Works ok.

Wrote a very simple WCF client to basically do the same thing but it does not work. I used Fiddler2 to see what is happening.

The Delphi application gets back basic text. My WCF application gets back content that is gzip compressed. This must be the default as I did not set this. When the response comes back there is no means to decompress the data.

I see many many web pages going into detail about setting gzip compression but nothing about disabling this.

The question is how can I get my WCF client to request from the GeoCoder site, a response in plain text (I know that compression is good etc) but in this instance I just want to see this working.

The sites WSDL is at http://rpc.geocoder.us/dist/eg/clients/GeoCoder.wsdl

My source code (its very elementary as I learning this stuff)

   using System;
   using System.Collections.Generic;
   using System.ComponentModel;
   using System.Data;
   using System.Drawing;
   using System.Linq;
   using System.Text;
   using System.Windows.Forms;
   using System.ServiceModel;
   using GeoCodeTest.ServiceReference1;

   namespace GeoCodeTest
   {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private GeocoderResult[] LocationResult = null;
            private GeoCode_PortTypeClient proxy = null;

            private void btnGo_Click(object sender, EventArgs e)
            {
                LocationResult = proxy.geocode(txtLocation.Text); // always returns a null !!!
                geocoderResultBindingSource.DataSource = LocationResult;
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                proxy = new GeoCode_PortTypeClient("GeoCode_Port");
            }
        }
   }

This is the app.config file that was generated.

 <?xml version="1.0" encoding="utf-8" ?>
   <configuration>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="GeoCode_Binding" closeTimeout="00:01:00" openTimeout="00:01:00"
                        receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                        bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                        maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                        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://rpc.geocoder.us/service/soap/" binding="basicHttpBinding"
                    bindingConfiguration="GeoCode_Binding" contract="ServiceReference1.GeoC开发者_运维问答ode_PortType"
                    name="GeoCode_Port" />
            </client>
        </system.serviceModel>
   </configuration>

Is there something I can add/remove/change to the app.config so that a WCF client request will ask for plain text like the Delphi application?


Server should compress the response only if your request contains HTTP header Accept-Encoding: gzip. Check your request with Fiddler. If this header is not present in your request, the compression is controlled by some custom mechanism.

Only WCF 4 HTTP based client sends that HTTP header because it is out of the box able to decompress the message. If it doesn't there is something wrong with the message. You can turn off this feature by defining custom binding:

<bindings>
  <customBinding>
    <binding name="BasicWithNoCompression">
      <textMessageEncoding messageVersion="Soap11" />
      <httpTransport decompressionEnabled="false" />
    </binding>
  </customBidning>
</bindings>


I had a quick look at this, and it is NOT the compression that is causing the issue. As already mentioned, WCF clients (v4) can decompress the data fine. In fact, if you modify the outgoing request message header and remove the "gzip, deflate" from the Accept-Encoding header the response comes back already uncompressed, however the data is still not present in the return object. There seems to be an issue with the way the client has generated its datacontract I think.

If I have some more time, I will have a closer look but it may take sometime to find out where the exact mismatch(s) occur.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜