Consume PM Web services from ASP.Net

Original article: http://forum.processmaker.com/viewtopic.php?f=9&t=3836

I got working PM web services with ASP.Net.

When I create a employee on our HR system, a PM user will be created automatically so the new employee can access PM to make leave requests, expenses reports, etc.
Also, the newly created PM user is automatically assigned to the “Employees” group.

First, you need to “add a new service reference” to your web application on Visual Studio (version 2008 in my case). Indicate the address(URL) of the web service server of your web server installation (e.g. http://mydomain.com/sysworkflow/en/green/services/wsdl2, you better check this http://wiki.processmaker.com/index.php/ … b_Services).
Give the reference a namespace you can remember(“ProcessMaker”, in my case).

This will modify your web.config file, where you can see diferent settings for your web service.

<system.serviceModel>
<bindings>
<customBinding>
<binding name="ProcessMakerServiceSoap">
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap12" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<httpTransport manualAddressing="false" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous" realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://mydomain.com:80/sysworkflow/en/green/services/soap2" binding="customBinding" bindingConfiguration="ProcessMakerServiceSoap" contract="ProcessMaker.ProcessMakerServiceSoap" name="ProcessMakerServiceSoap" />
</client>
</system.serviceModel>

Later, I created a class under App_Code folder. The code is below:

Imports Microsoft.VisualBasic
Imports ProcessMaker//web service namespace, the same you set at "add a new service reference"

Public Class PMakerWSDL

Public Shared Function crearUsuario(ByVal _Empleado As Object) As String

Dim _loginresponse As loginResponse = PMakerWSDL.login()
If _loginresponse.status_code = "0" Then
Dim _password As String
If _Empleado.Idempleado.ToString.Length > 7 Then
_password = _Empleado.Idempleado.Substring(2)
Dim _createuserresponse As createUserResponse = PMakerWSDL.createUser(_loginresponse.message, _Empleado.Idempleado, _Empleado.Nombres + " " + _Empleado.Nombres2, _Empleado.Apellidopaterno + " " + _Empleado.Apellidomaterno, _Empleado.Correo, "PROCESSMAKER_OPERATOR", _
_password)
If _createuserresponse.userUID IsNot Nothing And _createuserresponse.userUID <> "" Then
System.Web.HttpContext.Current.Session("_EsNuevo") = "0"
Dim _groupId As String = "3274407494c983348ca3613003993997" 'EMPLOYEES GROUP ID
Dim _assignusertogroupresponse As assignUserToGroupResponse = PMakerWSDL.assignUserToGroup(_loginresponse.message, _createuserresponse.userUID, _groupId)
If _assignusertogroupresponse.status_code <> 0 Then
Return "3"
Else
Return "4"
End If
Else
Return "2"
End If
Else
Return "1"
End If
Else
Return "0"
End If
End Function

Public Shared Function login() As loginResponse
Dim _pmakersoapclient As New ProcessMakerServiceSoapClient()
Dim _response As New loginResponse
Dim _message As String = ""
Dim _version As String = ""
Dim _timestamp As String = ""
Dim _statuscode As String = ""
Dim _username As String = "administratorusername"
Dim _password As String = "md5:myMD5encryptedpasswordblablabla"
_statuscode = _pmakersoapclient.login(_username, _password, _message, _version, _timestamp)
_response.version = _version
_response.timestamp = _timestamp
_response.message = _message
_response.status_code = _statuscode
Return _response
End Function

Public Shared Function createUser(ByVal _sessionID As String, ByVal _username As String, ByVal _firstname As String, _
ByVal _lastname As String, ByVal _email As String, _
ByVal _role As String, ByVal _password As String) As createUserResponse
Dim _pmakersoapclient As New ProcessMakerServiceSoapClient()
Dim _response As New createUserResponse
Dim _statuscode As String = ""
Dim _message As String = ""
Dim _timestamp As String = ""
Dim _userUID As String = ""
_statuscode = _pmakersoapclient.createUser(_sessionID, _username, _firstname, _lastname, _email, "PROCESSMAKER_OPERATOR", _
_password, _message, _userUID, _timestamp)
_response.message = _message
_response.status_code = _statuscode
_response.timestamp = _timestamp
_response.userUID = _userUID
Return _response
End Function

Public Shared Function createDepartment(ByVal _sessionID As String, ByVal _name As String, _
ByVal _parentUID As String) As createDepartmentResponse
Dim _pmakersoapclient As New ProcessMakerServiceSoapClient()
Dim _response As New createDepartmentResponse
Dim _statuscode As String = ""
Dim _message As String = ""
Dim _timestamp As String = ""
Dim _departmentID As String = ""
_statuscode = _pmakersoapclient.createDepartment(_sessionID, _name, _parentUID, _message, _departmentID, _timestamp)
_response.message = _message
_response.status_code = _statuscode
_response.timestamp = _timestamp
_response.departmentUID = _departmentID
Return _response
End Function

Public Shared Function assignUserToGroup(ByVal _sessionId As String, ByVal _userId As String, ByVal _groupId As String) As assignUserToGroupResponse
Dim _pmakersoapclient As New ProcessMakerServiceSoapClient()
Dim _response As New assignUserToGroupResponse() 'GENERIC PROCESS MAKER RESPONSE <message name="pmResponse">
Dim _message As String = ""
Dim _timestamp As String = ""
Dim _statuscode As String = ""
_statuscode = _pmakersoapclient.assignUserToGroup(_sessionId, _userId, _groupId, _message, _timestamp)
_response.status_code = _statuscode
_response.message = _message
_response.timestamp = _timestamp
Return _response
End Function

Public Shared Function assignUserToDepartment(ByVal _sessionId As String, ByVal _userId As String, ByVal _departmentId As String) As assignUserToGroupResponse
Dim _pmakersoapclient As New ProcessMakerServiceSoapClient()
Dim _response As New assignUserToGroupResponse()
Dim _message As String = ""
Dim _timestamp As String = ""
Dim _statuscode As String = ""
Dim _manager As String = ""
_manager = getDeparmentManager(_departmentId)
_statuscode = _pmakersoapclient.assignUserToDepartment(_sessionId, _userId, _departmentId, _manager, _message, _timestamp)
_response.status_code = _statuscode
_response.message = _message
_response.timestamp = _timestamp
Return _response
End Function

Public Shared Function getDeparmentManager(ByVal _departmentId As String) As String
Dim _manager As String = ""
'TO DO
Return _manager
End Function

Public Shared Function setUserInactive(ByVal _userId As String) As String
'TO DO
Return "1"
End Function
End Class

Then, you can use this from your ASP.Net web forms like this:

_BLEmployee.CreateEmployee(_Entity);//Create employee on HR system
//PROCESS MAKER INTEGRATION
string _respuestaPM="PM";
_respuestaPM = PMakerWSDL.crearUsuario(_Entity);//Create user on ProcessMaker

Other people have had trouble with this, so check:
viewtopic.php?f=9&t=2526&start=0&hilit=visual+studio
http://social.msdn.microsoft.com/Forums … ae9e57b64a

I also had this trouble when I added it as a web reference and not like a service reference.
Adding it as a service reference fixed the problem.

References:
ProcessMaker web services: http://wiki.processmaker.com/index.php/ … b_Services
Add service reference on VS 2008: http://chakkaradeep.wordpress.com/2007/08/13/add-service-reference-in-vs-2008/

http://blog.somecreativity.com/2008/07/22/add-service-reference-option-not-appearing-in-visual-studio-2008/

5 responses to this post.

  1. Posted by Noe Alcantara on 25 octubre, 2011 at 10:01

    Tambien necesito web services para PM desde visual studio 2010

    Responder

  2. Posted by Noe on 25 octubre, 2011 at 16:08

    Nathan.
    como lo hiciste?… yo lo probe tambien visual 2008 y me pintan errores de
    -loginResponse no esta definido
    -createUserResponse no esta definido
    -System.Web.HttpContext.Current.Session
    y muchos mas errores

    Importe el web services , y lo referencie bien.
    te puedo dejar para que lo veas porfavor.

    desde ya gracias.

    cuanto agrego la referencia lo encuentra y muestra esto:

    “ProcessMakerService” Description
    Documentation
    ProcessMaker Web Service

    Methods
    assignUserToDepartment ( sessionId As string , userId As string , departmentId As string , manager As string ) As integer

    assignUserToGroup ( sessionId As string , userId As string , groupId As string ) As integer

    caseList ( sessionId As string ) As caseListStruct

    createDepartment ( sessionId As string , name As string , parentUID As string ) As integer

    createGroup ( sessionId As string , name As string ) As integer

    createUser ( sessionId As string , userId As string , firstname As string , lastname As string , email As string , role As string , password As string ) As integer

    departmentList ( sessionId As string ) As departmentListStruct

    executeTrigger ( sessionId As string , caseId As string , triggerIndex As string , delIndex As string ) As integer

    getCaseInfo ( sessionId As string , caseId As string , delIndex As string ) As integer

    getVariables ( sessionId As string , caseId As string , variables As variableStruct ) As integer

    groupList ( sessionId As string ) As groupListStruct

    importProcessFromLibrary ( sessionId As string , processId As string , version As string , importOption As string , usernameLibrary As string , passwordLibrary As string ) As integer

    inputDocumentList ( sessionId As string , caseId As string ) As inputDocumentListStruct

    inputDocumentProcessList ( sessionId As string , processId As string ) As inputDocumentProcessListStruct

    login ( userid As string , password As string ) As integer

    newCase ( sessionId As string , processId As string , taskId As string , variables As variableListStruct ) As integer

    newCaseImpersonate ( sessionId As string , processId As string , userId As string , variables As variableListStruct ) As integer

    outputDocumentList ( sessionId As string , caseId As string ) As outputDocumentListStruct

    processList ( sessionId As string ) As processListStruct

    reassignCase ( sessionId As string , caseId As string , delIndex As string , userIdSource As string , userIdTarget As string ) As integer

    removeDocument ( sessionId As string , appDocUid As string ) As integer

    removeUserFromGroup ( sessionId As string , userId As string , groupId As string ) As integer

    roleList ( sessionId As string ) As roleListStruct

    routeCase ( sessionId As string , caseId As string , delIndex As string ) As integer

    sendMessage ( sessionId As string , caseId As string , from As string , to As string , cc As string , bcc As string , subject As string , template As string ) As integer

    sendVariables ( sessionId As string , caseId As string , variables As variableListStruct ) As integer

    systemInformation ( sessionId As string ) As integer

    taskCase ( sessionId As string , caseId As string ) As taskCaseStruct

    taskList ( sessionId As string ) As taskListStruct

    triggerList ( sessionId As string ) As triggerListStruct

    userList ( sessionId As string ) As userListStruct

    *******************y el xml del web service muestra esto*********************************

    ProcessMaker Web Service

    *******gracias

    Responder

  3. Debes revisar que versión de PM estás usando. Algunas funciones del webservice talvez ya no existen (loginResponse,createUserResponse)
    Sobre System.Web.HttpContext.Current.Session, debes importar la referencia System.Web e importarla con Imports System.Web

    Responder

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

A %d blogueros les gusta esto: