IFBO C# Visual Studio 2008 client (Appendix G)

C# implementation of the if_rig Appendix G code snippet.

Reference: http://www.codeproject.com/KB/cs/multipart_request_C_.aspx

using System;
using System.Web;
using System.Xml;
using System.IO;
using System.Net;
using System.Text;

namespace ifboClient {

public class ifboClient {

private static string PostRequest(System.Uri uri, string requestXml) {

string response = null;

// We need to do this so the Ventyx servlet on the unix side will process the request.
// This simulates using the Java PostMethod class.
byte[] buffer = Encoding.ASCII.GetBytes("envName=UTF8&request=" + System.Web.HttpUtility.UrlEncode(requestXml));

HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(uri);

//Our method is post, otherwise the buffer (postvars) would be useless
WebReq.Method = "POST";

//We use form contentType, for the postvars.
WebReq.ContentType = "application/x-www-form-urlencoded";

//The length of the buffer (postvars) is used as contentlength.
WebReq.ContentLength = buffer.Length;

//We open a stream for writing the postvars
Stream PostData = WebReq.GetRequestStream();

//Now we write, and afterwards, we close. Closing is always important!
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();

//Get the response handle, we have no true response yet!
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();

//Now, we read the response (the string), and output it.
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);
response = _Answer.ReadToEnd();

return response;
}

static void Main() {

string IFBOXML = String.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE InboundRequest [ <!ELEMENT InboundRequest (APIHeader, BusinessObject)> <!ENTITY % APIHeader SYSTEM \"http://apifw//xml/APIHeader.Inbound.Request.V060000.dtd\"> %APIHeader; <!ENTITY % BusinessObject SYSTEM \"http://apifw//xml/WorkOrder.Create.Request.V060000.dtd\"> %BusinessObject; ]><InboundRequest><APIHeader ReplyTypeOK=\"A\" ReplyTypeError=\"N\"><apiAPIVersion>V060000</apiAPIVersion><apiBusinessObject>WorkOrder</apiBusinessObject><apiBusObjectMethod>Create</apiBusObjectMethod><apiBusObjectVersion>V060000</apiBusObjectVersion><apiUserID>PassPortID</apiUserID> <apiExtSystemID></apiExtSystemID><apiExtRequestID></apiExtRequestID><apiRoutingInfo></apiRoutingInfo></APIHeader><BusinessObject><WoHeader><Facility>TBL</Facility><WorkOrderType>CA</WorkOrderType><WoDescription>test IFBO</WoDescription><Planner>Planner</Planner><WoPriority>99</WoPriority><ProjectNbr>0001066</ProjectNbr></WoHeader></BusinessObject></InboundRequest>");

//System.Uri m_IfboUri = new System.Uri("https://server:SSLport/apifw/APIFWAdapterServlet");
System.Uri m_IfboUri = new System.Uri("http://server:port/apifw/APIFWAdapterServlet");

string response = PostRequest(m_IfboUri, IFBOXML);

Console.WriteLine("response=" + response);

}

}
}