Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have the following code to create a web service.
<pre lang="c#">[WebMethod]
        public string EncryptText1(string plaintext)
        {

            ASCIIEncoding textConverter = new ASCIIEncoding();
            byte[] key = textConverter.GetBytes("2a1c907916add59edffb3a4b");
            byte[] IV = textConverter.GetBytes("00000000");
            byte[] clearData = Encoding.ASCII.GetBytes(plaintext);
            byte[] cipherData = EncryptText(clearData, key, IV);
            return Convert.ToBase64String(cipherData);
        }
    [WebMethod]
    public byte[] EncryptText(byte[] clearData, byte[] Key, byte[] IV)
    {

        MemoryStream ms = new MemoryStream();
        TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
        tdes.Mode = CipherMode.ECB;
        tdes.Padding = PaddingMode.PKCS7;
        ICryptoTransform alg = tdes.CreateEncryptor(Key, IV);
        CryptoStream cs = new CryptoStream(ms, alg, CryptoStreamMode.Write);
        cs.Write(clearData, 0, clearData.Length);
        cs.FlushFinalBlock();
        cs.Close();
        byte[] encryptedData = ms.ToArray();
        return encryptedData;
    }

I have the following code to access the web service in php 

PHP
<?php
$enc_wsdl = "http://172.18.0.75/EncryptionWS/EncryptionWS.asmx?wsdl";
$enc_client = new SoapClient($enc_wsdl);
$finalstring = $enc_client->EncryptText1("SomeUserName");
print_r($finalstring);
?>


but I am getting the following error: 

Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> String reference not set to an instance of a String. Parameter name: s in C:\xampp\htdocs\dotnetwebservice\index.php:4 Stack trace: #0 C:\xampp\htdocs\dotnetwebservice\index.php(4): SoapClient->__call('EncryptText1', Array) #1 C:\xampp\htdocs\dotnetwebservice\index.php(4): SoapClient->EncryptText1('SomeUserName') #2 {main} thrown in C:\xampp\htdocs\dotnetwebservice\index.php on line 4
Posted
Updated 28-Apr-15 0:16am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900