无法使用soap访问php中的.net webservice [英] Unable to access .net webservice in php using soap

查看:62
本文介绍了无法使用soap访问php中的.net webservice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码来创建一个Web服务。

< pre lang =c#> [WebMethod] 
public string EncryptText1(string明文)
{

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);
返回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();
返回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]服务器无法处理请求。 --->字符串引用未设置为String的实例。参数名称:s在C中:\ xampp \\\ htdocs \ _dotnetwebservice \ index.php:4堆栈跟踪:#0 C:\ xampp \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > __ call('EncryptText1',Array)#1 C:\ xampp\htdocs \ divnetwebservice \ index.php(4):SoapClient->在C中抛出的EncryptText1('SomeUserName')#2 {main} :第4行的\ xampp \htdocs \dotnetwebservice \ index.php  

解决方案

enc_wsdl = http://172.18.0.75/EncryptionWS/EncryptionWS.asmx?wsdl;


enc_client = new SoapClient(

enc_wsdl);


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
$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

解决方案

enc_wsdl = "http://172.18.0.75/EncryptionWS/EncryptionWS.asmx?wsdl";


enc_client = new SoapClient(


enc_wsdl);


这篇关于无法使用soap访问php中的.net webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆