// GrooveOutputFilter.cs
// John Bristowe (john.bristowe@empowered.com) - February 12th, 2003
// This work is licensed under the Creative Commons Attribution-ShareAlike
// License (http://creativecommons.org/licenses/by-sa/1.0)
using Microsoft.Web.Services;
using Microsoft.Win32;
using System;
using System.Xml;
namespace Groove.Web.Services
{
public class GrooveOutputFilter : SoapOutputFilter
{
public override void ProcessMessage(SoapEnvelope envelope)
{
if (envelope == null) throw new ArgumentNullException("envelope");
bool isLocalInvocation = envelope.Context["target"] == null;
XmlElement soapHeader = envelope.CreateHeader();
XmlElement grooveHeader = envelope.CreateElement("GrooveHeader", "http://webservices.groove.net/Groove/1.0/Core/");
soapHeader.AppendChild(grooveHeader);
XmlElement grooveHeaderTtl = envelope.CreateElement("TimeToLive", "http://webservices.groove.net/Groove/1.0/Core/");
if (envelope.Context["ttl"] == null) grooveHeaderTtl.InnerText = "30";
else grooveHeaderTtl.InnerText = envelope.Context["ttl"].ToString();
grooveHeader.AppendChild(grooveHeaderTtl);
if (isLocalInvocation)
{
RegistryKey grooveRegistryKey = Registry.CurrentUser.OpenSubKey("Software\\Groove Networks, Inc.\\Groove\\WebServices");
if (grooveRegistryKey != null)
{
string nonce = (string) grooveRegistryKey.GetValue("WebServicesNonce");
XmlElement grooveNonce = envelope.CreateElement("GrooveNonce", "http://webservices.groove.net/Groove/1.0/Core/");
grooveNonce.InnerText = nonce;
grooveHeader.AppendChild(grooveNonce);
}
string identityUrl = envelope.Context["identityUrl"] as string;
if (identityUrl != null)
{
XmlElement grooveIdentityUrl = envelope.CreateElement("GrooveIdentityURL", "http://webservices.groove.net/Groove/1.0/Core/");
grooveIdentityUrl.InnerText = identityUrl;
grooveHeader.AppendChild(grooveIdentityUrl);
}
}
else
{
string target = envelope.Context["target"] as string;
XmlElement grooveTarget = envelope.CreateElement("TargetURL", "http://webservices.groove.net/Groove/1.0/Core/");
grooveTarget.InnerText = target;
}
}
}
}