Content Negotiation در WCF
نویسنده: مسعود پاکدل
تاریخ: ۱۳۹۳/۰۳/۰۶ ۹:۴۵
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
install-package WcfRestContrib
[ServiceContract]
public interface IBooksService
{
[OperationContract]
void AddBook(string isbn, Book book);
} [ServiceContract]
public interface IBooksService
{
[WebInvoke(UriTemplate = "/{isbn}", Method=Verbs.Put)]
[WebDispatchFormatter]
[OperationContract]
void AddBook(string isbn, Book book);
....
} [WebDispatchFormatterConfiguration("application/xml")]
[WebDispatchFormatterMimeType(typeof(WcfRestContrib.ServiceModel.Dispatcher.Formatters.PoDataContract), "application/xml", "text/xml")]
[WebDispatchFormatterMimeType( typeof(WcfRestContrib.ServiceModel.Dispatcher.Formatters.DataContractJson), "application/json")]
[WebDispatchFormatterMimeType( typeof(WcfRestContrib.ServiceModel.Dispatcher.Formatters.FormUrlEncoded), "application/x-www-form-urlencoded")]
public class Books : IBooksService
{
public void AddBook(string isbn, Book book)
{
}
}
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="webFormatter"
type="WcfRestContrib.ServiceModel.Configuration.WebDispatchFormatter.ConfigurationBehaviorElement, WcfRestContrib,
Version=x.x.x.x, Culture=neutral, PublicKeyToken=89183999a8dc93b5"/>
</behaviorExtensions>
</extensions>
<serviceBehaviors>
<behavior name="Rest">
<webFormatter>
<formatters defaultMimeType="application/xml">
<formatter mimeTypes="application/xml,text/xml"
type="WcfRestContrib.ServiceModel.Dispatcher.Formatters.PoxDataContract, WcfRestContrib"/>
<formatter mimeTypes="application/json"
type="WcfRestContrib.ServiceModel.Dispatcher.Formatters.DataContractJson, WcfRestContrib"/>
<formatter mimeTypes="application/x-www-form-urlencoded"
type="WcfRestContrib.ServiceModel.Dispatcher.Formatters.FormUrlEncoded, WcfRestContrib"/>
</formatters>
</webFormatter>
</behavior>
</serviceBehaviors>
</system.serviceModel> [WebDispatchFormatter(WebDispatchFormatter.FormatterDirection.Outgoing)]