c# - Problem communicating with Janrain "auth_info" service in WCF -


so i'm stuck @ point. trying communicate janrain's "auth_info" service. in fact, start, i'm trying "error" message/object/'.jsthingy' when surf directly in browser:

https://rpxnow.com/api/v2/auth_info

but want wcf call.

according fiddler, content type of information @ url text/javascript. however, can tell, wcf doesn't give me option when calling through wcf. 2 options: webmessageformat.json, or webmessageformat.xml.

i following error in visual studio:

invalidoperationexception unhandled user code - incoming message has unexpected message format 'raw'. expected message formats operation 'xml', 'json'. can because webcontenttypemapper has not been configured on binding. see documentation of webcontenttypemapper more details.

wtf? can wcf do this? (i suspect more manual solution ahead)

janrain's online code examples little bit lacking in c# examples.

their documentation link on auth_info here https://rpxnow.com/docs#auth_info

the address of auth_info service here:

https://rpxnow.com/api/v2/auth_info

[testmethod] public void calljanrain() {     var x = new janrainproxy("https://rpxnow.com/api/v2");      x.getauthinfo("", ""); //the params apikey, , token. not passing either @ moment want able know how @ least handle error first. after all, *browser* @ least got it..  }     [servicecontract]     public interface ijanraincontract     {         [operationcontract(name="auth_info")]         [webinvoke(bodystyle = webmessagebodystyle.wrappedrequest, requestformat = webmessageformat.json, responseformat =  webmessageformat.xml)]         janrainauthinfo getauthinfo(string apikey, string token);     }    [datacontract]     public class janrainauthinfo     {         [datamember(name="identifier")]         public string identifier { get; set; }     }   public class janrainproxy: clientbase<ijanraincontract>     {         public janrainproxy(string url, webhttpsecuritymode securitymode = webhttpsecuritymode.transport)             : base(constructendpoint(url, securitymode))         {          }           //janraincontract     public janrainauthinfo getauthinfo(string apikey, string token)     {          return base.channel.getauthinfo(apikey, token);     }      // method constructs webhttpbinding endpoint appropriate     // settings talking our services.     private static serviceendpoint constructendpoint(string serviceuri, webhttpsecuritymode securitymode)     {         var contract = contractdescription.getcontract(typeof(ijanraincontract));         var binding = new webhttpbinding(securitymode);                           //{                           //    maxbufferpoolsize = 524288000,                           //    maxreceivedmessagesize = 65536000                           //};          var address = new endpointaddress(serviceuri);         var endpoint = new serviceendpoint(             contract,             binding,             address);          var webhttpbehavior = new webhttpbehavior()         {             defaultbodystyle = webmessagebodystyle.wrapped,             defaultoutgoingrequestformat = webmessageformat.json,             defaultoutgoingresponseformat = webmessageformat.json,             automaticformatselectionenabled = true,             faultexceptionenabled = true         };          endpoint.behaviors.add(webhttpbehavior);         return endpoint;     } } 

i'm figuring perhaps should leave contenttype @ json , tweak behavior, or binding.

ok.. looks needed add custom contenttypemapper on binding

after declaring binding added following:

    webcontenttypemapper custommapper = new jsoncontenttypemapper();     binding.contenttypemapper = custommapper; 

here's custom mapper:

  public class jsoncontenttypemapper : webcontenttypemapper     {         public override webcontentformat                    getmessageformatforcontenttype(string contenttype)         {             if (contenttype == "text/javascript")             {                 return webcontentformat.raw;             }             else             {                 return webcontentformat.json;             }         }     } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -