Speaking At GatorMUG March 19, 2009

Since I graduated from FSU, it makes it hard to speak at any group that uses "Gator" in their name, but to rub it in even worst having to do it in Gainesville, Fl too. So next Thursday I will swallow my pride and head out to GatorMUG to share about the cool features of Entity Framework. It should be a good time, because I hear these guys are already hooked on LINQ To SQL. I cannot blame them at this time, however Microsoft has stated that EF will be their future direction for O/R Modeling, so I hope to squash out any misconceptions. Any other geeked out FSU Alumni out there? Please show up!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: BayerWhite
Posted on: 3/13/2009 at 1:25 AM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (38) | Post RSSRSS comment feed

Calling Up WCF From Powershell

Microsoft Dynamics has a standard API called a Business Connector and while there is no activity, it sometimes it drops the connection. I was hoping to build logic that would catch these types of situations, however I could not get the BC to play fair. I already had a WCF service that communicated with the BC I just needed to add a script that I could set up as a scheduled task and some Dynamics static calls that I could use to ping the BC. If you don't have Powershell you can pick it up here.

My first challenge was how to call the WCF service. I decided to use Powershell by which I found a great resource for calling WCF services. After reviewing info I was able to create the following script...

svcutil.exe http://localhost:8731/DAX/BusConnect/
csc /t:library BusConnect.cs /r:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\System.ServiceModel.dll"
[Reflection.Assembly]::LoadWithPartialName("System.ServiceModel")
[Reflection.Assembly]::LoadFrom("$pwd\BusConnect.dll")
$NetTcpBinding = new-object System.ServiceModel.NetTcpBinding
$endpoint = new-object System.ServiceModel.EndpointAddress("net.tcp://localhost:8085/DAX/BusConnect")
$secMode = new-object System.ServiceModel.SecurityMode
$NetTcpBinding.Security.Mode = $secMode;
$NudgeService = new-object BusConnectorClient($NetTcpBinding, $endpoint)
$NudgeService.DAXNudge()

So essentially you...

  1. Create the proxy code through the SDK's svcutil command
  2. Compile the code referencing the ServiceModel.dll
  3. Use reflection to load the compiled dll referencing System.ServiceModel
  4. Create the binding...In this case I used TCP
  5. Setup an SecurityMode...In this case there is 'None'
  6. Assign it to the binding
  7. Create the new service call
  8. Call my method on the service

To create the script open up Notepad and paste in the script. When you save the file use the .PS1 extension. Now to make sure your script knows about SvcUtil and where to find System.ServiceModel, you want to find where they are located on the system and added to the Environment Variables, "Path". You can do this easily by left clicking on Computer and going to properties then Advanced System Settings and clicking on the Advanced tab

Now that the paths are added to the Environment Variables, you need to setup PowerShell to run scripts...Follow the guide here. Once setup, run the scripts by starting up powershell following the guide.

Finally, after I know the script runs I need to add it as a scheduled task. For Vista, watch this quick video. To set it up on Server 2003, it should look like this

  1. "Run as:" should be the account the task will "run as"
  2. "Run" Powershell path and the file to run...ex. C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe .\NudgeBusConn.PS1
  3. "Start in:" Where the powershell script is located...ex. "C:\Program Files\Company\BusinessConnectorWakeUp"

Something that is extremely important is that when I pushed this to production, I excluded the SDK from the server. For security reasons this is not a could practice. Instead, just copy the proxy files and compiled code to prod and take out the script that was building these files. Overall I have had a great taste of what powershell can do. I think it is very powerful and can be used many ways for automation or writing code and thinking outside the box. More importantly, Powershell activities will be introduced within WF 4.0, so now seemed like a great time to understand senarios for when to use it.

 

Currently rated 1.9 by 8 people

  • Currently 1.875/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: BayerWhite
Posted on: 3/4/2009 at 3:36 AM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (350) | Post RSSRSS comment feed