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;




                 return  WebContentFormat .Default;





And change the app.config:

 <?xml version= "1.0 " encoding= "utf-8 " ?> 




       <!--<endpoint address="" 





                 name="ArcGISREST" />--> 

       <endpoint address= " "

                 binding= "customBinding "

                 bindingConfiguration= "ArcGISBinding2 "

                 behaviorConfiguration= "ArcGIS "

                 contract= "TestRestWCFClient.IArcGISApi "

                 name= "ArcGISREST " /> 




         <binding name= "ArcGISBinding " maxReceivedMessageSize= "10000000 "/> 



         <binding name= "ArcGISBinding2 "> 

           <webMessageEncoding webContentTypeMapperType= "TestRestWCFClient.JsonContentTypeMapper, TestRestWCFClient, Version=, Culture=neutral, PublicKeyToken=null " /> 

             <httpTransport manualAddressing= "true " maxReceivedMessageSize= "10000000 " /> 






         <behavior name= "ArcGIS "> 








No comments: