How to implement Parlay X in .NET

How to implement Parlay X in .NET

In this tutorial, I will explain how to implement Send SMS Interface of Parlay X 2.1 APIs using C#.

Before proceeding, I would like to tell you that Parlay X is a set of standard low-level SOAP based Web API’s used by many telecom service providers. The implementation of interfaces might differ from provider to provider. Before jumping onto the code, ask you telecom provider to share the WSDL’s and Endpoints of the services and their interfaces respectively.

Interface : sendSMS

This interface defines operations to send various types of SMS messages and to subsequently poll for delivery status. There are generally four properties defined in it.

  • addresses specifies the destination address of the short message.
  • senderName is optional and specifies the sender name. The value is a string that is displayed on the user’s terminal as the originator of the message.
  • charging specifies the charging information.
  • receiptRequest is optional and is specified when the application requires receiving notifications of the SMS delivery status. It is a SimpleReference structure that indicates the application endpoint and interface used for notification of delivery receipt, and a correlator that uniquely identifies the sending request.

Below is the sample SOAP request which needs to be generated and sent over. Only header portion has to be created manually, and rest of it would be generated automatically.

1

 

2

Step 1: Using provided WSDL, Add a web reference in your C# project

3

Step 2: Creating a custom SOAP header and passing it to every single SOAP request.

 

[XmlTypeAttribute(Namespace = “http://www.huawei.com.cn/schema/common/v2_1″, TypeName=”v2”)]

public class RequestSOAPHeader : SoapHeader

{

public string spId { get; set; }

public string spPassword { get; set; }

public string serviceId { get; set; }

public string timeStamp { get; set; }

public string OA { get; set; }

public string FA { get; set; }

}

 

In the References.cs file of the web service, add a field of RequestSOAPHeader type as shown below

 

public RequestSOAPHeader authCred;

4

 

 

Add the attribute around the sendSms method inside references.cs file

[System.Web.Services.Protocols.SoapHeader(“authCred”, Direction = SoapHeaderDirection.InOut)]

Step 3: Instantiate all objects shown below and call the sendSMS method


private static void SendSMS()

{

RequestSOAPHeader authentication = new RequestSOAPHeader();

string timestamp = GetTimeStamp();

authentication.spId = <YOUR SP Id>;

authentication.spPassword = GetMD5Hash(“<Your SP Id>” + “< Your Password >” +  timestamp);

authentication.serviceId = “<Your Service Id>”;

authentication.timeStamp = timestamp;

authentication.OA = “tel:09810205066”;  // Any telephone number

authentication.FA = “tel:09810205066”;  // Any telephone number

 

SendSmsService.SendSmsService svc = new SendSmsService.SendSmsService();

svc.authCred = authentication;

 

SimpleReference simple = new SimpleReference();

simple.endpoint “<Your Interface endpoint url>”;

simple.interfaceName = “SmsNotification”;

simple.correlator = “123”; //Put anything

 

sendSms msg = new sendSms();

msg.senderName = “974”; // It is basically the access code

msg.addresses = new string[] { “9810205066” };  telephone number

msg.message = “Test Parlay X”;

msg.receiptRequest = simple;

 

sendSmsResponse res = svc.sendSms(msg);

Console.WriteLine(res.result);

}

 

Some providers require password to be hashed, for that you can use the GetMD5Hash function written below

private static string GetMD5Hash(string sInputString)

{

ASCIIEncoding enc = new ASCIIEncoding();

byte[] buffer = enc.GetBytes(sInputString);

MD5 md = new MD5CryptoServiceProvider();

byte[] hash = md.ComputeHash(buffer);

string sResult = “”;

foreach (byte b in hash)

{

sResult += b.ToString(“x2”);

}

return sResult;

}

 

private static string GetTimeStamp()

{

return DateTime.Now.ToString(“yyyyMMddHHmmss”);

}

I hope this example helps in implementing other interfaces of Parlay X APIs too.

ParlayClient Source Code

5 thoughts on “How to implement Parlay X in .NET

  1. thek44a2@gmail.com'
    The Hoang
    says:
    Reply

    Dear Ankit Sharma,
    I am working on ParlayX task. My provider does not give me the WSDL file or WSDL url, just give me SOAP object structure and url of the service. So, it is difficult to create the proxy manually. Could you send me the ParlayClient project.

    Thanks you in advanced!
    Regards,
    The Hoang.

  2. vulong1987@yahoo.com'
    Long Pham
    says:
    Reply

    Hello.

    Can you share your source code in this article?
    Thanks.

  3. Ankit Sharma
    says:
    Reply

    Hi, I know its pretty late to reply. But I have now attached the source code link at the end of this article as well.

    http://exceptionlesscode.com/wp-content/uploads/2013/05/ParlayClient.zip

  4. viresh1983@gmail.com'
    Viresh Kadulkar
    says:
    Reply

    Can i get a sample code to implement Webservice in ASP.net

Leave a reply

Your email address will not be published. Required fields are marked *