WCF Service for iCal Returns

How do I get my service written with WCF to return iCal? The examples I see use both xml or json, and the way to format the response. What is the best way to return other types of reaction bodies?

+3
source share
2 answers

Something like that:

[WebGet(UriTemplate="{id}.ics")]
[OperationContract]
Stream GetCalendar(int id)
{
   WebOperationContext.Current.OutgoingResponse.ContentType="text/calendar";

   //Now just return the appropriate data in iCal format in the Stream...
}

So now you can do an HTTP GET, for example. yourService.svc / 123.ics and return iCal.

The reason for this is that "Stream" has a special wrapper in WCF REST (used for non-XML, non-JSON responses).

Remember that for this you need to use the behavior of WebHttpBinding and WebHttp.

+3
source

iCal XML JSON ( ) WCF:

[ServiceContract]
interface IMyCalService
{
  [OperationContract]
  string GetiCal(.......);
}

, , XML- iCal ( JSON). WCF SOAP.

REST WCF, iCal URL- - WCF Rest Starter Kit ( .NET 3.0/3.5). iCal, , , XML- iCal.

+1

Source: https://habr.com/ru/post/1719318/


All Articles