Hi,
My goal is to create a whole raft of New requests based on the data held in our old workflow system. So I will want to loo through my old requests and for each one raise a new WFGen request and populate some of the data.
If I use a link in a web browser I can successfully create a blank new request. What I really need is to pass it a context as well so fields will be populated and do this from c# code within a for each loop.
My issue appears to be finding the right credentials to use. If I use my windows logon and password I get an authentication message. That surprised me because when I use the url without any credentials it must surely be using windows authentication.
The code I have used is pretty much a copy of the code in the Documentation with a couple of minor changes to allow it to be run from a windows form rather than a web procedure.
Here is a snippet of what I am trying
ContextParameters myCPs = new ContextParameters();
ContextParameter myParam = new ContextParameter();
myParam.Name = "SELLECT_EMPLOYEE_TXTEMPLOYEENAME";
myParam.Value = "Simon Breeze";
myParam.Direction = ContextParameter.Directions.In;
myCPs.Add(myParam);
myCPs.Update();
string myContext = myCPs.GetXml();
string apURL = Url + "&L=" + Language + "&ProcessName=" + ProcessName
+ "&RequesterName=simon.breeze&Test=" + Test;
System.Net.NetworkCredential mycred = new System.Net.NetworkCredential
(UserName, Password, UserDomain);
System.Net.CredentialCache myCache = new System.Net.CredentialCache();
myCache.Add(new Uri(Url),"Basic",mycred);
//Prepare request
System.Net.HttpWebRequest httpWebReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(apURL);
httpWebReq.Method = "Post";
//Set Authentication
httpWebReq.Credentials = myCache;
//Set Context info
string postData = "CONTEXT=" + WebUtility.UrlEncode(myContext);
System.Text.ASCIIEncoding encoding = new ASCIIEncoding();
Byte[] Buffer = encoding.GetBytes(postData);
//Set the contenttype of the data being posted
httpWebReq.ContentType = "application/x-www-form-urlencoded";
httpWebReq.ContentLength = postData.Length;
//Send the context
System.IO.Stream myStream = httpWebReq.GetRequestStream();
myStream.Write(Buffer, 0, Buffer.Length);
myStream.Close();
HttpWebResponse httpWebResp = null ;
try
{
httpWebResp = (System.Net.HttpWebResponse)httpWebReq.GetResponse();
}
catch(WebException ex)
{
MessageBox.Show(ex.ToString());
}
Thanks
Simon