无法使用soap访问php中的.net webservice
我有以下代码来创建web服务无法使用soap访问php中的.net webservice,php,asp.net,web-services,soap,webservice-client,Php,Asp.net,Web Services,Soap,Webservice Client,我有以下代码来创建web服务 [WebMethod] public string EncryptText1(string plaintext) { ASCIIEncoding textConverter = new ASCIIEncoding(); byte[] key = textConverter.GetBytes("2a1c907916add59edffb3a4b"); byte[]
[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]服务器已关闭
无法处理请求。-->字符串引用未设置为
字符串的实例。参数名称:s in
C:\xampp\htdocs\dotnewebservice\index.php:4堆栈跟踪:0
C:\xampp\htdocs\dotnetwebservice\index.php4:
SoapClient->\调用'EncryptText1',数组1
C:\xampp\htdocs\dotnetwebservice\index.php4:
SoapClient->EncryptText1'SomeUserName'2{main}被抛出
第4行的C:\xampp\htdocs\dotnetwebservice\index.php
尽管如此,如果我使用soap,我还是会遇到同样的错误,但是我使用ajax调用解决了这个问题。 代码如下: $.ajax{ 类型:POST,, 网址:http://172.18.3.0/EncryptDecrypt/Encryptdecrypt.asmx/Encrypt, //网址:http://172.18.0.75/EncryptionWS/EncryptionWS.asmx/EncryptText1, 数据:JSON.stringify{'nameorpassword':'ww'}, contentType:application/json;字符集=utf-8, 数据类型:json, 成功:函数msg { msg.d; }
};您使用的SoapClient类是错误的。请阅读手册:你能建议我如何使用这个吗?我是第一次使用这个。我不知道如何使用soapclient