Hi,
I am trying to programmatically raise new items in a process with a context from c#. I have used the example code from the documentation in resources with a couple of small changes. I persuaded the request to use my default credentials with the following three lines
httpWebReq.UseDefaultCredentials = true;
httpWebReq.PreAuthenticate = true;
httpWebReq.Credentials = CredentialCache.DefaultCredentials;
This gets me past the authentication messages I got earlier but now I get a response with some redirection errors and no item is created.
\nRedirection error\n\n\n\n Redirection error The requested page cannot be foundAnd here is my code
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.NetworkCredential mycred = new System.Net.NetworkCredential
// (UserName, Password, UserDomain);
//System.Net.CredentialCache myCache = new System.Net.CredentialCache();
//myCache.Add(new Uri(Url),"Windows",mycred);
//Prepare request
System.Net.HttpWebRequest httpWebReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(apURL);
httpWebReq.Method = "Post";
////Set Authentication
//httpWebReq.Credentials = myCache;
httpWebReq.UseDefaultCredentials = true;
httpWebReq.PreAuthenticate = true;
httpWebReq.Credentials = CredentialCache.DefaultCredentials;
//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());
}
string respCode = "OK"; // response code variable
// Check the response status code is OK
if (respCode != httpWebResp.StatusCode.ToString())
{
// Display the Error details
MessageBox.Show("Error:" + httpWebResp.StatusCode);
}
else
{
// Gets the stream associated with the response
httpWebResp = (System.Net.HttpWebResponse)httpWebReq.GetResponse();
System.IO.StreamReader myReader = new System.IO.StreamReader(httpWebResp.GetResponseStream());
string response = myReader.ReadToEnd();
httpWebResp.Close();
// Display response message
MessageBox.Show(response);
}
Thanks for any help.