emkt Browserless Coding For C#.Net and Excel

Similar documents
BULK HTTP API DOCUMENTATION

The Open Core Interface SDK has to be installed on your development computer. The SDK can be downloaded at:

Configuration Web Services for.net Framework

PULSE - API. The purpose of this document is to provide example requests and responses for all relevant Pulse services requests

Main Game Code. //ok honestly im not sure, if i guess its a class ment for this page called methodtimer that //either uses the timer or set to timer..

Starting with FRITZ!OS 5.50 a session ID is also required in all three cases.

To start we will be using visual studio Start a new C# windows form application project and name it motivational quotes viewer

Consuming SAIT API via ITS ESB from web / desktop application

MVC - Repository-And-Unit-Of-Work

CALCULATOR APPLICATION

Use Document-Level Permissions for browser-based forms in a data view

Connecting VirtueMart To PayPal (Live)

COOKBOOK Sending an in Response to Actions

// Precondition: None // Postcondition: The address' name has been set to the // specified value set;

IST311 Chapter13.NET Files (Part2)

INTRODUCTION ACCESS 2010

ISF Getting Started. Table of Contents

WAVV 2005 Colorado Springs, CO. VSE.NET Programming. Handouts. Agenda. Page 1. .NET Programming Example with VSE

You can call the project anything you like I will be calling this one project slide show.

My Practice Profile Attestation QUICK REFERENCE

CSIS 1624 CLASS TEST 6

The contents of this document are directly taken from the EPiServer SDK. Please see the SDK for further technical information about EPiServer.

IBSDK Quick Start Tutorial for C# 2010

Memory Usage. Chapter 23

Appendix A Programkod

Probid B2B programmer guide

Hands-On Lab. Lab 05: LINQ to SharePoint. Lab version: Last updated: 2/23/2011

Your Company Name. Tel: Fax: Microsoft Visual Studio C# Project Source Code Output

DB Browser UI Specs Anu Page 1 of 15 30/06/2004

Web services CSCI 470: Web Science Keith Vertanen Copyright 2014

MCSA Universal Windows Platform. A Success Guide to Prepare- Programming in C# edusum.com

Item 18: Implement the Standard Dispose Pattern

Engr 123 Spring 2018 Notes on Visual Studio

TARGETPROCESS PLUGIN DEVELOPMENT GUIDE

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

Quick Start Guide. Version 3.0

EL-USB-RT API Guide V1.0

Table of Contents Web Service Specification (version 1.5)

Login to the FRITZ!Box Web Interface

Networking Haim Michael. All Rights Reserved.

Your Company Name. Tel: Fax: Microsoft Visual Studio C# Project Source Code Output

CSC 355 PROJECT 4 NETWORKED TIC TAC TOE WITH WPF INTERFACE

My Practice Profile Attestation QUICK REFERENCE

CSC 415 ONLINE PHOTOALBUM: THE SEQUEL ASP.NET VERSION

erequest How to apply guide

How to create an Add-In extension.dll file and make it available from Robot pull down menu. (language C#)

More Skills 11 Export Queries to Other File Formats

Accessing the Progress OpenEdge AppServer. From Progress Rollbase. Using Object Script

10.) Click on the Security tab in Internet Options. 11.) Then click on Trusted Sites. 12.) Click on the Custom level button.

SETTING UP YOUR.NET DEVELOPER ENVIRONMENT

Function: function procedures and sub procedures share the same characteristics, with

SETTING UP YOUR.NET DEVELOPER ENVIRONMENT

Hands-On Lab. Lab 13: Developing Sandboxed Solutions for Web Parts. Lab version: Last updated: 2/23/2011

Writing Your First Autodesk Revit Model Review Plug-In

Hello everyone! Page 1. Your folder should look like this. To start with Run your XAMPP app and start your Apache and MySQL.

Web services. CSCI 470: Web Science Keith Vertanen

Asynchronous Programming Model (APM) 1 Calling Asynchronous Methods Using IAsyncResult 4 Blocking Application Execution by Ending an Async Operation

0Acknowledgement. This application has been developed with the cooperation of the Inter-agency Group for Child Mortality Estimation.

Nonprofit Technology Collaboration. Mail Merge

KWizCom Corporation. imush. Information Management Utilities for SharePoint. Printing Feature. Application Programming Interface (API)

Click on the empty form and apply the following options to the properties Windows.

VISIONTRACKER FREQUENTLY ASKED QUESTIONS FAQ

Registering for classes Help

Representing Recursive Relationships Using REP++ TreeView

Maximo Version 7.1 How-To

API Guide MSS-8 and MVS-16

Job Aid. Enter bid Using XML Upload Functionality

Set Up a Two Factor Authentication with SMS.

Start Visual Studio, start a new Windows Form project under the C# language, name the project BalloonPop MooICT and click OK.

SMS Gatewa y Interface

Before you attempt to connect to IFAS, there are a few settings that you will have to change in Internet Explorer.

User Manual Appointment System

More Skills 12 Create Web Queries and Clear Hyperlinks

Reference Services Division Presents. Excel Introductory Course

Creating SDK plugins

Answer on Question# Programming, C#

Apex TG India Pvt. Ltd.

Start Visual Studio, create a new project called Helicopter Game and press OK

מ ע " ב םילעפמו תוכרעמ רימש

SOAP Introduction Tutorial

Web services CSCI 470: Web Science Keith Vertanen Copyright 2013

SURVEYOR/400. Users Guide. Copyright , LINOMA SOFTWARE LINOMA SOFTWARE is a division of LINOMA GROUP, Inc.

Workflow V2.8.1 Administrator and User Guide February 2015

Microsoft Access 2013

Office 2010: New Features Course 01 - The Office 2010 Interface

Design Of Human Computer Interfaces Assignment 1- Hello World. Compliance Report

Internet Explorer 9.x and Above for Windows

Ordering & Order Status

ODBC Setup MS Access 2007 Overview Microsoft Access 2007 can be utilized to create ODBC connections. This page will show you the steps to create an

Rollbase SOAP API Examples

C:\homeworks\PenAttention_v13_src\PenAttention_v13_src\PenAttention4\PenAttention\PenAttention.cs 1 using System; 2 using System.Diagnostics; 3 using

CS708 Lecture Notes. Visual Basic.NET Object-Oriented Programming. Implementing Client/Server Architectures. Part (I of?) (Lecture Notes 5A)

Page 7A TRENDS Installation (for Excel 2007 or Excel 2010) Excel 2007 Excel 2010

Table of Contents. I. How do I register for a new account? II. How do I log in? (I already have a MyJohnDeere.com account.)

Module 2: Managing Your Resources Lesson 5: Configuring System Settings and Properties Learn

Visual Basic/C# Programming (330)

1 SEARCHING FOR A MEMBER SEARCHING FOR A WI ADDING A NEW MEMBER HOW TO ADD A DUAL MEMBER... 9

Industry Access Portal MUNICIPALITY MODULE User Guide

Visual Presenter Visual Webcaster

FläktGroup Revit Plugin User guide

Transcription:

emkt Browserless Coding For C#.Net and Excel Browserless Basic Instructions and Sample Code 7/23/2013

Table of Contents Using Excel... 3 Configuring Excel for sending XML to emkt... 3 Sandbox instructions for developing emkt XML... 5 Sample Excel code for the Sandbox environment:... 6 Sample Excel code for the Production environment:... 7 Executing the Excel code... 8 Using C#... 8 Configuring C# for emkt... 8 C# emkt Class... 9 C# Sample code for the Sandbox that utilizes the class... 12 C# Sample code for Production that utilizes the class... 12 Page 2

Using Excel Configuring Excel for sending XML to emkt #1 Open Excel #2 Configure Excel to contain the Developer tab. A) Press the Excel File button Press Here B) Press the Excel Options link Page 3

C) Check the Show Developer tab in Ribbon option #3 Once the Developer tab is on the toolbar then select the Developer tab and then select the Visual Basic button. #4 Next, select the Tools from the menu and then choose References. Page 4

#5 Scroll down the pop-up list and locate the Microsoft WinHTTP Services, version 5.x and check the box and press OK. NOTE: If you are unable to locate the WinHTTP service then you probably have to install/register the winhttp.dll that is associated with this service. In order to install/register the winhttp.dll, follow these 2 steps. However, you will need System Admin rights of your computer to perform these steps: - Go to the 'Start' menu, type 'Run' in the 'Start Search' box and press 'Enter.' Type 'Regsvr32 'C:\Windows\System32\Winhttp.dll' in the 'Run' window and press 'Enter' to register the DLL. Click 'Yes' in the pop-up to confirm the registration of a new DLL. - Reboot your PC. Sandbox instructions for developing emkt XML #1 From the Developer Tab, press the Insert button and then add an ActiveX button to your spreadsheet as shown: #2 Click on the button and it should create an empty CommandButton1_Click Page 5

procedure for you. #3 Add the contents of the procedure shown below to your procedure. #4 Modify the code to contain the appropriate user name and password. #5 Modify the code to contain your emkt XML and the correct date. Sample Excel code for the Sandbox environment: Note: The XML at the top of the Excel routines are hardcoded queries for testing purposes. You might want to obtain the data from a spreadsheet cell or from a text file or by some other means. Private Sub CommandButton1_Click() Dim owinhttp As WinHttpRequest Dim sxml As String Set owinhttp = New WinHttpRequest Dim result As Variant 'Hardcoded XML to obtain Market Results. You could obtain this info 'or part of the info like the date from a spreadsheet cell or a flat 'file. The double quotes are to get the string itself to be able to 'contain a quote. sxml = "<?xml version=""1.0""?>" & _ "<Envelope xmlns=""http://schemas.xmlsoap.org/soap/envelope/"">" & _ "<Header/>" & _ "<Body>" & _ "<QueryRequest xmlns=""http://emkt.pjm.com/emkt/xml"">" & _ "<QueryMarketPrices type=""public"" day=""2013-07-01"">" & _ "<All/>" & _ "</QueryMarketPrices>" & _ "</QueryRequest>" & _ "</Body>" & _ "</Envelope>" With owinhttp 'Only Uncomment this next line if you need to go through a 'Firewall 'Call.SetProxy(2, "myproxy.mycompany.com:80","*.yourco.com") 'Call.SetTimeouts(300000, 300000, 300000, 300000) 'Sandbox Call.Open("POST", "https://emkttrn.pjm.com/emkt/xml/query") Call.SetCredentials("user", "password", 0) Call.SetRequestHeader("POST", "/emkt/xml/query HTTP/1.1") 'Sandbox Call.SetRequestHeader("HOST", "emkttrn.pjm.com") Page 6

Call.SetRequestHeader("Content-Type", "text/xml") Call.SetRequestHeader("Content-Length", Len(sXML)) Call.SetRequestHeader("SOAPAction", "/emkt/xml/query") Call.Send(sXML) 'Wait for the response asynchronously. Call.WaitForResponse 'These next 2 lines display the response text in a popup window. 'You could also store to a cell or to a flat file result =.ResponseText MsgBox result Call.Abort End With End Sub Sample Excel code for the Production environment: Private Sub CommandButton1_Click() Dim owinhttp As WinHttpRequest Dim sxml As String Set owinhttp = New WinHttpRequest Dim result As Variant 'Hardcoded XML to obtain Market Results. You could obtain this info 'or part of the info like the date from a spreadsheet cell or a flat 'file. The double quotes are to get the string itself to be able to 'contain a quote. sxml = "<?xml version=""1.0""?>" & _ "<Envelope xmlns=""http://schemas.xmlsoap.org/soap/envelope/"">" & _ "<Header/>" & _ "<Body>" & _ "<QueryRequest xmlns=""http://emkt.pjm.com/emkt/xml"">" & _ "<QueryMarketPrices type=""public"" day=""2013-07-01"">" & _ "<All/>" & _ "</QueryMarketPrices>" & _ "</QueryRequest>" & _ "</Body>" & _ "</Envelope>" With owinhttp 'Only Uncomment this next line if you need to go through a 'Firewall 'Call.SetProxy(2, "myproxy.mycompany.com:80","*.yourco.com") 'Call.SetTimeouts(300000, 300000, 300000, 300000) 'production Call.Open("POST", "https://emkt.pjm.com/emkt/xml/query") Call.SetCredentials("user", "password", 0) Call.SetRequestHeader("POST", "/emkt/xml/query HTTP/1.1") 'production Page 7

Call.SetRequestHeader("HOST", "emkt.pjm.com") Call.SetRequestHeader("Content-Type", "text/xml") Call.SetRequestHeader("Content-Length", Len(sXML)) Call.SetRequestHeader("SOAPAction", "/emkt/xml/query") Call.Send(sXML) 'Wait for the response asynchronously. Call.WaitForResponse 'These next 2 lines display the response text in a popup window. 'You could also store to a cell or to a flat file result =.ResponseText MsgBox result Call.Abort End With End Sub Executing the Excel code #1 From within the Developer tab, Press the Design Mode button to exit out of design mode. #2 Press the button that you had added to the spreadsheet. Your code should then execute the code associated with that button. It will connect to emkt and it will submit the XML. Using C# Configuring C# for emkt A C# class was developed for the purposes of connecting to emkt and being able to send and receive XML. #1 Open Visual Studio. Note: Code was developed using Visual Studio 10 version 4.0 #2 Copy the code below into a text file and save the file under a name and ensure the file has the.cs extension. #3 Create a project, and add the class file created above to your project. #4 Invoke the various methods of the class to accomplish the sending and Page 8

receiving of XML to emkt. (Described later in the document) C# emkt Class using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Runtime.InteropServices; using System.Net; using System.Windows.Forms; using System.Threading; namespace emktbrowserless public class emkttransfer : IDisposable public enum XMLTypes Query, Submit ; private XMLTypes xmltype = XMLTypes.Query; private string soapaction = "/emkt/xml/query"; private bool disposed = false; public void Dispose() Dispose(true); GC.SuppressFinalize(this); protected virtual void Dispose(bool disposing) if (!disposed) if (disposing) // dispose-only, i.e. non-finalizable logic Connection = null; GC.Collect(); // shared cleanup logic disposed = true; ~emkttransfer() Dispose(false); public emkttransfer(string userstr, string passwordstr) user = userstr; password = passwordstr; public XMLTypes XMLType set Page 9

xmltype = value; if (xmltype == XMLTypes.Query) soapaction = "/emkt/xml/query"; else soapaction = "/emkt/xml/submit"; private StringBuilder xmlinputfilecontents = new StringBuilder(""); private StringBuilder responsedata = new StringBuilder(""); private StringBuilder xmloutputfilecontents = new StringBuilder(""); public string ResponseData get return responsedata.tostring(); private string password = ""; private string user = ""; public string Password get return password; set password = value; public string User get return user; set user = value; private HttpWebRequest Connection = null; private string url; public string WebURL get return url; set url = value; if (Connection == null) Connection = (HttpWebRequest)WebRequest.Create(url); public string xmlinputfilecontents set xmlinputfilecontents.append(value); get return xmlinputfilecontents.tostring(); public string xmloutputfilecontents Page 10

set xmloutputfilecontents.append(value); get return xmloutputfilecontents.tostring(); private bool SetupConnectionData() bool connectionconfigured = false; if (user!= "" && password!= "") Connection.ContentType = "text/xml"; Connection.ProtocolVersion = System.Net.HttpVersion.Version10; Connection.Method = "POST"; Connection.Headers.Set("SOAPAction", soapaction); NetworkCredential PJMCredentials = new NetworkCredential(); PJMCredentials.UserName = user; PJMCredentials.Password = password; Connection.Credentials = PJMCredentials; connectionconfigured = true; Connection.Timeout = Timeout.Infinite; else MessageBox.Show("You must first provide a username and password"); return connectionconfigured; private void GetResponseData() WebResponse WebResponseObject = Connection.GetResponse(); Stream StreamResponseObject = WebResponseObject.GetResponseStream(); StreamReader StreamReaderObject = new StreamReader(StreamResponseObject); responsedata.append(streamreaderobject.readtoend()); //Close all stream objects StreamResponseObject.Close(); StreamReaderObject.Close(); WebResponseObject.Close(); public string xmlfilereader(string filespec) if (!File.Exists(filespec)) throw new Exception("Unable to locate specified file: " + filespec); using (StreamReader streamreader = new StreamReader(filespec)) return(streamreader.readtoend()); public void Upload(string uploadstring) Page 11

try if (!SetupConnectionData()) return; Stream poststream = Connection.GetRequestStream(); string sxml; sxml = uploadstring; byte[] bytearray = Encoding.ASCII.GetBytes(sXML); poststream.write(bytearray, 0, bytearray.length); poststream.close(); //Assign the response object of 'WebRequest' to a 'WebResponse' variable. GetResponseData(); catch (Exception e) MessageBox.Show("General Exception" + e.message, "General Exception", MessageBoxButtons.OK); C# Sample code for the Sandbox that utilizes the class using (emkttransfer emkt = new emkttransfer("username", "password")) emkt.weburl = "https://emkttrn.pjm.com/emkt/xml/query"; emkt.xmltype = emkttransfer.xmltypes.query; emkt.xmlinputfilecontents = emkt.xmlfilereader(@"c:\personal\sample.xml"); //Send up the XML input file contents to emkt emkt.upload(emkt.xmlinputfilecontents); //This is the response back from emkt string testresult = emkt.responsedata; C# Sample code for Production that utilizes the class using (emkttransfer emkt = new emkttransfer("username", "password")) emkt.weburl = "https://emkt.pjm.com/emkt/xml/query"; emkt.xmltype = emkttransfer.xmltypes.query; emkt.xmlinputfilecontents = emkt.xmlfilereader(@"c:\personal\sample.xml"); //Send up the XML input file contents to emkt emkt.upload(emkt.xmlinputfilecontents); //This is the response back from emkt string testresult = emkt.responsedata; Page 12