Saturday, February 19, 2011

Solved: The incoming message has an unexpected message format 'Raw'.

As I mentioned in my earlier post the ArcGIS Server REST API returned "plain/text" causing the WCF client to give error message: "The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml'; 'Json'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details." Found a forum post that helped solve the problem:
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: