http - WCF Interoperability with other services, content type is text/html -
http - WCF Interoperability with other services, content type is text/html -
i trying create wcf client operates http rest endpoint not based on microsoft technologies. wcf-foo pretty weak, don't understand doing incorrectly... i've created service contract looks this...
[servicecontract] public interface ifilters { [operationcontract] [webget(uritemplate = "/api/filter.getavailable.xml?api_user={username}&api_key={password}")] string getavailablefilters(string username, string password); }
which seek , run this...
public string run(string username, string password) { var binding = new basichttpbinding(); binding.messageencoding = wsmessageencoding.text; binding.security.mode = basichttpsecuritymode.transport; var endpointaddress = new endpointaddress("https://sendgrid.com"); ifilters proxy = channelfactory<ifilters>.createchannel(binding, endpointaddress); var result = ""; using (proxy idisposable) { result = proxy.getavailablefilters(username, password); } homecoming result; }
when run code, exception says...
the content type text/html; charset=utf-8 of response message not match content type of binding (text/xml; charset=utf-8). if using custom encoder, sure iscontenttypesupported method implemented properly. first 1024 bytes of response were: ...
now if seek , access web browser (with different credentials), xml doc i'm looking for... https://sendgrid.com/api/filter.getavailable.xml?api_user=foo&api_key=bar
what doing incorrectly?
edit:
this final working solution...
public filters run(string username, string password) { var binding = new webhttpbinding(webhttpsecuritymode.transport); var endpointaddress = new endpointaddress("https://sendgrid.com"); var mill = new channelfactory<ifilters>(binding, endpointaddress); factory.endpoint.behaviors.add(new webhttpbehavior()); var proxy = factory.createchannel(); using (proxy idisposable) { var results = proxy.getavailablefilters(username, password); homecoming results; } }
on client side using basichttpbinding soap binding not rest binding. should seek using webclient class instead
http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx
or webchannelfactory
http://msdn.microsoft.com/en-us/library/bb908674.aspx
wcf http binding uritemplate
Comments
Post a Comment