private void ShowCreateTokensUI()
        {
            CreateTokensRequestDto createTokenRequest = new CreateTokensRequestDto();

            try
            {
                Console.WriteLine("=====================Request building start======================");
                createTokenRequest.CustomerTransactionID = Read_String_Input("Please Enter Customer Transaction ID:", true);
                createTokenRequest.CustomerCode          = Read_String_Input("Please enter the CustomerCode:", false);
                createTokenRequest.Username       = Read_String_Input("Please enter the Username:"******"Please enter the Password:"******"Please enter the Number of tokens:");
                createTokenRequest.TokenData      = Read_LongString_Input("Please enter the TokenData:", true);
                createTokenRequest.TokenName      = Read_String_Input("Please enter the TokenName:", true);
                createTokenRequest.ValidUntilUTC  = Read_ValidUtc_Date("Enter ValidUntilUTC:", "Year(Ex:2025):-", "Month(Between 1-12)Ex:For 1 Enter 01 :-", "Day(Between 1-31)Ex: For 1 Enter 01:-", "Hour(Between 0-23)Ex: For 1 Enter 01:-", "Minute(Between 0-59)Ex: 1 Enter 01:-", "Seconds(Between 0-59)Ex:For 1 Enter 01:-");
                createTokenRequest.MiscData       = Read_String_Input("Please Enter MiscData:", true);
                Console.WriteLine("=====================Request building End======================");
                var CreateTokensSvc = _serviceProvider.GetService <ICreateTokenWebServiceClient>();
                var tokenizationServiceResponseDto = CreateTokensSvc.CallTokenWebService(createTokenRequest);
                if (tokenizationServiceResponseDto != null)
                {
                    var response = tokenizationServiceResponseDto as CreateTokensResponseDto;
                    Console.WriteLine("=====================Response Start======================");
                    Console.WriteLine("Response:");
                    Console.Write(PrettyXml(response.PageContent) + "\n");
                    Console.WriteLine("=====================Response End======================");
                }
                else
                {
                    Console.WriteLine("Response is null, Please check with input values given and try again");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while CreateTokens : " + ex.Message.ToString());
            }
        }
Esempio n. 2
0
        public CreateTokensResponseDto CallTokenWebService(CreateTokensRequestDto request)
        {
            CreateTokensResponseDto response = new CreateTokensResponseDto();
            int?   statusCode  = null;
            string pageContent = string.Empty;

            try
            {
                string soapAction = "http://www.magensa.net/Token/ITokenService/CreateTokens";
                string soapBody   = $@"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:tok=""http://www.magensa.net/Token/"" xmlns:tok1=""http://schemas.datacontract.org/2004/07/TokenWS.Core"" xmlns:sys=""http://schemas.datacontract.org/2004/07/System.Collections.Generic"">
  <soapenv:Header/>
  <soapenv:Body>
    <tok:CreateTokens>
      <tok:CreateTokensRequest>
        <tok1:AdditionalRequestData>
          <sys:KeyValuePairOfstringstring>
            <sys:key></sys:key>
            <sys:value></sys:value>
          </sys:KeyValuePairOfstringstring>
        </tok1:AdditionalRequestData>
        <tok1:Authentication>
          <tok1:CustomerCode>{request.CustomerCode}</tok1:CustomerCode>
          <tok1:Password>{request.Password}</tok1:Password>
          <tok1:Username>{request.Username}</tok1:Username>
        </tok1:Authentication>
        <tok1:CustomerTransactionID>{request.CustomerTransactionID}</tok1:CustomerTransactionID>
        <tok1:MiscData>{request.MiscData}</tok1:MiscData>
        <tok1:NumberOfTokens>{request.NumberOfTokens}</tok1:NumberOfTokens>
        <tok1:TokenData>{request.TokenData}</tok1:TokenData>
        <tok1:TokenName>{request.TokenName}</tok1:TokenName>
        <tok1:ValidUntilUTC>{request.ValidUntilUTC}</tok1:ValidUntilUTC>
      </tok:CreateTokensRequest>
    </tok:CreateTokens>
  </soapenv:Body>
</soapenv:Envelope>";


                MagensaSOAPClient soapClient     = new MagensaSOAPClient(host: Host, certificateFileName: CertificateFileName, certificatePassword: CertificatePassword);
                HttpWebResponse   webResponse    = soapClient.CallWebService(soapAction, soapBody);
                Stream            responseStream = webResponse.GetResponseStream();
                using (StreamReader sr = new StreamReader(responseStream))
                {
                    response.StatusCode  = (int)webResponse.StatusCode;
                    response.PageContent = sr.ReadToEnd();
                }
                responseStream.Close();
                webResponse.Close();
            }
            catch (WebException ex)
            {
                HttpStatusCode sCode = ((HttpWebResponse)ex.Response).StatusCode;
                response.StatusCode  = (int)sCode;
                response.PageContent = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
            }
            catch (Exception ex)
            {
                response.StatusCode  = null;
                response.PageContent = ex.Message;
            }
            return(response);
        }