JSON and WebInvoke The problem can be solved using a WebContentTypeMapper created a class:
public class JsonContentTypeMapper :WebContentTypeMapper
{
public override WebContentFormat
GetMessageFormatForContentType(string contentType)
{
if (contentType == "text/plain; charset=utf-8" )
{
return WebContentFormat .Json;
}
else
{
return WebContentFormat .Default;
}
}
}
And change the app.config:
<?xml version= "1.0 " encoding= "utf-8 " ?>
<configuration>
<system.serviceModel>
<client>
<!--<endpoint address="http://server.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Median_Household_Income/MapServer/4/query"
binding="webHttpBinding"
bindingConfiguration="ArcGISBinding"
behaviorConfiguration="ArcGIS"
contract="TestRestWCFClient.IArcGISApi"
name="ArcGISREST" />-->
<endpoint address= "http://server.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Median_Household_Income/MapServer/4/query "
binding= "customBinding "
bindingConfiguration= "ArcGISBinding2 "
behaviorConfiguration= "ArcGIS "
contract= "TestRestWCFClient.IArcGISApi "
name= "ArcGISREST " />
</client>
<bindings>
<webHttpBinding>
<binding name= "ArcGISBinding " maxReceivedMessageSize= "10000000 "/>
</webHttpBinding>
<customBinding>
<binding name= "ArcGISBinding2 ">
<webMessageEncoding webContentTypeMapperType= "TestRestWCFClient.JsonContentTypeMapper, TestRestWCFClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null " />
<httpTransport manualAddressing= "true " maxReceivedMessageSize= "10000000 " />
</binding>
</customBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name= "ArcGIS ">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
No comments:
Post a Comment