Hi jangins101,
I have written a VB.Net application that creates a number of Personnel Actions and connects to Lawson to apply them. It is tricky to do so if need any help let me know.
John P.
Ok, explain to me what your trying to do, and what you have gotten to work so far.
OK here is how i am connecting,
Public Overridable Function SubmitPAtoLawson(ByVal http As String)Dim mainReq, LoginReq As HttpWebRequestDim cred As NetworkCredentialDim mainResp, LoginResp As HttpWebResponseDim qryReturn As String Dim mainStream, loginStream As StreamReaderDim xmlDoc As XmlDocumentDim postData As String Dim postStream As StreamWriterDim cookies As CookieContainerConst LAWSON_UID As String = "xxxxx" ' must be set to a valid employee with an RD30 Const LAWSON_PWD As String = "xxxxxxxx" ' must be the above user's password loginStream = Nothing mainResp = Nothing mainStream = Nothing Try cred = New NetworkCredential(LAWSON_UID, LAWSON_PWD)' Send a GET request to the Lawson login page (need to get a session cookie) LoginReq = WebRequest.Create( LoginReq.Method = "http://xxxlawweb02.com/lawson/portal/")"GET" ' UserAgent MUST be set or an HTTP 500 error is returned LoginReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2)" LoginResp = LoginReq.GetResponse cookies = LoginReq.CookieContainer = cookies LoginResp.Cookies = LoginReq.CookieContainer.GetCookies(LoginReq.RequestUri) New CookieContainerTry loginStream = qryReturn = loginStream.ReadToEnd New StreamReader(LoginResp.GetResponseStream)Finally If Not IsNothing(loginStream) Then loginStream.Close()'Else ' ActionReturnMsg = "Unable to Login to Lawson. " & loginStream.ToString ' ActionReturnCode = "006" ' loginStream.Close() If Not IsNothing(LoginResp) Then LoginResp.Close()'Else 'ActionReturnMsg = "Invalid Response from Lawson. " & LoginResp.ToString 'ActionReturnCode = "007" 'LoginResp.Close() 'End If End Try ' Next send a POST request to the Lawson SSO servlet mainReq = WebRequest.Create( mainReq.Method = "http://xxxlawweb02.com/sso/SSOServlet")"POST" mainReq.ContentType = "application/x-www-form-urlencoded" mainReq.Credentials = cred mainReq.PreAuthenticate = True mainReq.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-us")'USERAGENT MUST BE SET OR AN HTTP 500 ERROR WILL BE RETURNED mainReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2)" ' build the string of POST data for the SSO Servlet. ' Note the _ssoOrigUrl parameter is what Lawson will redirect to and return XML from. postData = System.Web.HttpUtility.UrlEncode(http) "_ssoUser=" & LAWSON_UID & "&_ssoPass=" & LAWSON_PWD & "&_action=LOGIN&_fromLoginPage=FALSE&_language=en-us&_ssoOrigUrl=" & _' pass in the cookie container obtained from the LOGIN PAGE (critcal) mainReq.CookieContainer = cookies mainReq.ContentLength = Len(postData) ' Write the POST data to the stream postStream = New StreamWriter(mainReq.GetRequestStream)Try postStream.Write(postData.ToString) Finally postStream.Close() End Try 'Get the data as an HttpWebResponse object mainResp = mainReq.GetResponse() ' Convert the data into a string (assumes that you are requesting text) mainStream = qryReturn = mainStream.ReadToEnd() New StreamReader(mainResp.GetResponseStream())' load an XML doc with the returned data. xmlDoc = xmlDoc.LoadXml(qryReturn.ToString) New XmlDocumentReturn xmlDocIf IsNothing(xmlDoc) Then ActionReturnMsg = "Unable to execute Lawson API." ActionReturnCode = "001" Return Nothing End If ActionReturnMsg = ActionReturnCode = Catch ex As WebException"Unable execute Lawson DME call. " & ex.Message"002" Return Nothing Catch ex As Exception' unable to execute against the api ActionReturnMsg = ActionReturnCode = "Unable execute Lawson DME call. " & ex.Message"003" Return Nothing Finally End Try End Function' clean up open items
loginStream =
mainResp =
mainStream =
cred =
LoginReq = WebRequest.Create(
LoginReq.Method =
LoginReq.UserAgent =
LoginResp = LoginReq.GetResponse
cookies =
LoginReq.CookieContainer = cookies
LoginResp.Cookies = LoginReq.CookieContainer.GetCookies(LoginReq.RequestUri)
qryReturn = loginStream.ReadToEnd
mainReq = WebRequest.Create(
mainReq.Method =
mainReq.ContentType =
mainReq.Credentials = cred
mainReq.PreAuthenticate =
mainReq.Headers.Add(HttpRequestHeader.AcceptLanguage,
mainReq.UserAgent =
postData =
System.Web.HttpUtility.UrlEncode(http)
mainReq.CookieContainer = cookies
mainReq.ContentLength = Len(postData)
postStream =
postStream.Write(postData.ToString)
postStream.Close()
mainResp = mainReq.GetResponse()
qryReturn = mainStream.ReadToEnd()
xmlDoc =
xmlDoc.LoadXml(qryReturn.ToString)
ActionReturnMsg =
ActionReturnCode =
End
Let me know if this makes sense.
John, Thank you very much for posting your sample code. We are upgrading from 8.02 to LSF9 and we have around 10 applications that used to use the Lawson COM+ along with VB6 in 8.02 and your code example has given us an excellent starting point for converting all of these applications. You have saved us a lot of research and otherwise wasted time.
Thank you again, Shawn