[英]Unable to access .net webservice in php using soap
我有以下代碼來創建Web服務
[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;
}
我有以下代碼來訪問php中的Web服務
<?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);
?>
但我收到以下錯誤:
致命錯誤:未捕獲的SoapFault異常:[soap:Server]服務器無法處理請求。 --->字符串引用未設置為字符串的實例。 參數名稱:C:\\ xampp \\ htdocs \\ dotnetwebservice \\ index.php:4中的堆棧跟蹤:#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}放在第4行的C:\\ xampp \\ htdocs \\ dotnetwebservice \\ index.php中
如果使用肥皂仍然會出現相同的錯誤,但是我使用ajax調用解決了該問題。
下面是代碼:
$.ajax({ type: "POST", url: "http://172.18.3.0/EncryptDecrypt/Encryptdecrypt.asmx/Encrypt", //url: "http://172.18.0.75/EncryptionWS/EncryptionWS.asmx/EncryptText1", data: JSON.stringify({'nameorpassword': 'ww'}), contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { alert(msg.d); } });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.