.net - WCF: Using the same code for SOAP and JSON implementation? -
i have taken on development on .net wcf project. among other things, project contains 3 files:
iapi.cs <=
defining interfacesjsonapi.svc.cs <=
implementing interface jsonsoapapi.svc.cs <=
implementing interface soap
the 2 implementation files identical - @ least code in implementation of methods identical. quite new wcf programming, strikes me odd, need duplicate code, implement json soap.
is there way merge 1 implementation , let framework decide if data transported soap or json?
/ carsten
defines 2 endpoints, same contract service implementation. defines first use soap, second use json :
<service name="yourservice"> <endpoint address="rest" binding="webhttpbinding" contract="iyourservice" behaviorconfiguration="restbehavior"/> <endpoint address="soap" binding="wshttpbinding" contract="iyourservice"/> <endpoint address="mex" binding="mexhttpbinding" contract="imetadataexchange"/> </service> <endpointbehaviors> <behavior name="restbehavior"> <webhttp/> </behavior> </endpointbehaviors>
then there endpoint @ http://.../yourservice.svc/soap , @ http://.../yourservice.svc/rest
[edit] answer comment, said replace section :
<services> <service name="webapi.soapapi" behaviorconfiguration="apibehavior"> <endpoint address="basic" bindingnamespace="http://api.myservice.dk/basic" contract="webapi.iapi" binding="basichttpbinding" bindingconfiguration="apibinding" /> </service> <service name="webapi.jsonapi" behaviorconfiguration="apibehavior"> <endpoint address="web" bindingnamespace="http://api.myservice.dk/web" contract="webapi.iapi" binding="webhttpbinding" bindingconfiguration="apibinding" behaviorconfiguration="jsonbehavior" /> </service> </services>
by :
<services> <service name="webapi.uniqueapi" behaviorconfiguration="apibehavior"> <endpoint address="basic" bindingnamespace="http://api.myservice.dk/basic" contract="webapi.iapi" binding="basichttpbinding" bindingconfiguration="apibinding" /> <endpoint address="web" bindingnamespace="http://api.myservice.dk/web" contract="webapi.iapi" binding="webhttpbinding" bindingconfiguration="apibinding" behaviorconfiguration="jsonbehavior" /> </service> </services>
one service, 2 endpoints
Comments
Post a Comment