And the Simple Indigo Client
Next, we need a simple client to go with my service.
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.ServiceModel;
namespace InfoCardClient
{
//This replicates the services contract - just raw Messages
[ServiceContract]
interface IGenericMessageChannel
{
[OperationContract(IsOneWay = true, Action = "*")]
void Send(Message msg);
}
class SimpleClient
{
public SimpleClient()
{
}
void SendMessage(IGenericMessageChannel channel, string input)
{
XmlDocument contentDocument;
contentDocument = new XmlDocument();
contentDocument.LoadXml("" + input + " ");
XmlNodeReader content = new XmlNodeReader(contentDocument.DocumentElement);
MessageVersion messageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap11);
using (Message msg = Message.CreateMessage(messageVersion, "http://tempuri.org/ISimpleService/Receive", content))
{
try
{
channel.Send(msg);
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.ToString());
}
}
}
public void Invoke( string input)
{
using (ChannelFactorychannelFactory =
new ChannelFactory("InfoCardClientConfig"))
{
channelFactory.Open();
IGenericMessageChannel channel = channelFactory.CreateChannel();
SendMessage(channel, input);
channelFactory.Close();
}
}
}
}
I call this client from another class which is irrelevant to the InfoCard/Indigo magic.
No comments:
Post a Comment