Wednesday, February 3, 2010

Autodesk Map3d 2010 with WCF (III)

Author: Jonio, Dennis

The snippets below are an example for a client. It did take some time to research the parameters required for a long lived(8 hour) service. It turned out to be that two(2) parameters have to be set, InactivityTimeout and ReceiveTimeout. Needless to say these should match the service’s ServiceEndpoint configuration.

In general the way the service works is that you can send it data with any one(1) of three(3) different methods. I only employ one(1) of those methods in this case. If your application has “Subscribed” you will be sent via the callback method any and all output from the service. I really do not attempt to track the “state” of anything. As the book explains, and to say the least, state tracking is probably not the best way to expend your time and energy.

From Map3d's perspective the new, improved DataBridge is really a non issue. For all intent and purpose Map3d will see things the same way. I am sure that as time moves on the complexity of "if" and "case" statements will grow.
I plan on following this article with the complete DataBridge Version II.
Source code snippets for a client(C#):


public static IByteSrvcWCallback SrvcHost;
public static ByteSrvcCallbackImpl callbackImpl;
public static DuplexChannelFactory dcf;
public static Guid MyServicedName;
public static string MyPrefixForMap3dDQ = "MDADCLSSFYIO";
public static string AddressOfReliableSessionService = "net.tcp://localhost:9080/DataService";


public MainForm()
{
InitializeComponent();
NetTcpBinding ntb = new NetTcpBinding(SecurityMode.None, true);
ntb.ReliableSession.Enabled = true;
ntb.ReliableSession.Ordered = true;
ntb.ReliableSession.InactivityTimeout = new TimeSpan(0, 8, 0, 0);
ntb.ReceiveTimeout = new TimeSpan(0, 8, 0, 0);
callbackImpl = new ByteSrvcCallbackImpl();
InstanceContext ic = new InstanceContext(callbackImpl);
dcf = new DuplexChannelFactory(
ic,
ntb,
new EndpointAddress(AddressOfReliableSessionService));
SrvcHost = dcf.CreateChannel();
callbackImpl.OnGotControlPacket +=
new ByteSrvcCallbackImpl.GotControlPacket(WCF_RcvdSrvcControlPacket);
MyServicedName = Guid.Empty;
}

void WCF_RcvdSrvcControlPacket(byte[] ba)
{
byte[] x = callbackImpl.ControlPacket;
//
//Here is the callback
//Do something useful with the data that the Service has sent to you
//
}

public int WCF_SendToMap3dDataBridge(byte[] ba)
{
return SrvcHost.DQPipedIn(MyPrefixForMap3dDQ, ba);
}

private void btnSUBSCRIBE_Click(object sender, EventArgs e)
{
try
{
if (MyServicedName == Guid.Empty)
MyServicedName = SrvcHost.Subscribe();
}
catch (EndpointNotFoundException _epnfX)
{
AppendMessage("EndPoint ERROR: " + _epnfX.Message);
}
catch (System.Exception _eX)
{
AppendMessage("ERROR: " + _eX.Message);
}
}

private void btnUNSUBSCRIBE_Click(object sender, EventArgs e)
{
try
{
if (MyServicedName != Guid.Empty)
SrvcHost.UnSubscribe(MyServicedName);
MyServicedName = Guid.Empty;
}
catch (EndpointNotFoundException _epnfX)
{
AppendMessage("EndPoint ERROR: " + _epnfX.Message);
}
catch (System.Exception _eX)
{
AppendMessage("ERROR: " + _eX.Message);
}
}

No comments:

Post a Comment