php webservice调用时发生异常:System.Xml.XmlException: 根级别上的数据无效。 第 1 行,位置 1

abcde760 2014-04-28 05:05:53
[b]webservice中的方法:[/b]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Collections.Specialized;

public partial class TestPhpWebService : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void Button1_Click(object sender, EventArgs e)
{
SortedDictionary<string, string> sArray = new SortedDictionary<string, string>();
NameValueCollection coll;
coll = HttpContext.Current.Request.Params;
String[] requestItem = coll.AllKeys;

for (int i = 0; i < requestItem.Length; i++)
{
sArray.Add(requestItem[i], HttpContext.Current.Request.Params[requestItem[i]]);
}
string post_notify_data = HttpContext.Current.Request.Params.Get("notify_data");
//post_notify_data = post_notify_data.Replace(' ', '+');
string post_orderid = HttpContext.Current.Request.Params.Get("orderid");
string post_dealseq = HttpContext.Current.Request.Params.Get("dealseq");
string post_uid = HttpContext.Current.Request.Params.Get("uid");
string post_subject = HttpContext.Current.Request.Params.Get("subject");
string post_v = HttpContext.Current.Request.Params.Get("v");

insertdata(post_notify_data, post_orderid, post_dealseq, post_uid, post_subject, post_v);


}

public void insertdata(string post_notify_data, string post_orderid, string post_dealseq, string post_uid, string post_subject, string post_v)
{
string public_Key = ConfigurationManager.ConnectionStrings["publicKey"].ConnectionString; //取得公钥
string post_sign = "aaaa";
WebService.decryptWSDLtest phpWebService = new WebService.decryptWSDLtest();
string decrypt_data = phpWebService.verify_data(public_Key, post_sign, post_notify_data, post_orderid, post_dealseq, post_uid, post_subject, post_v);
}
}

[b]php中的代码:[/b]
<?php
require_once ("lib/nusoap.php");
$server = new soap_server ();
// 避免乱码
$server->soap_defencoding = 'UTF-8';
$server->decode_utf8 = false;
$server->xml_encoding = 'UTF-8';
$server->configureWSDL ('decryptWSDLtest', 'http://tempuri.org/'); // 打开 wsdl 支持
$server->register ('verify_data', // 方法名
array ("public_Key" => "xsd:string","post_sign" => "xsd:string",
"post_notify_data" => "xsd:string","post_orderid" => "xsd:string",
"post_dealseq" => "xsd:string","post_uid" => "xsd:string",
"post_subject" => "xsd:string","post_v" => "xsd:string"), // 参数,默认为 "xsd:string"
array ("return" => "xsd:string")); // 返回值,默认为 "xsd:string"
$HTTP_RAW_POST_DATA = isset ($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
//service 处理客户端输入的数据
$server->service ($HTTP_RAW_POST_DATA);

function verify_data($public_Key,$post_sign,$post_notify_data,$post_orderid,$post_dealseq,$post_uid,$post_subject,$post_v){
include('log4php/Logger.php');
include("Rsa.php");

//初始化log4php
$log = Logger::getLogger('myLogger');
$date = date('Y-m-d h:i:s');

Logger::configure(array(
'rootLogger' => array(
'appenders' => array('default'),
'level' => 'DEBUG'
),
'appenders' => array(
'default' => array(
'class' => 'LoggerAppenderFile',
'layout' => array(
'class' => 'LoggerLayoutSimple'
),
'params' => array(
'file' => 'myLog.log',
'append' => true
)
)
)
));


/*if($post_sign==""){
$log->warn($date." Unable to get required value");
return "failed";
}*/

$publicKey = $public_key;
$post_sign = $post_sign;//base64_decode($post_sign);

//对输入参数根据参数名排序,并拼接为key=value&key=value格式;
$parametersArray = array();

$parametersArray['notify_data'] = $post_notify_data;
$parametersArray['orderid'] = $post_orderid;
$parametersArray['dealseq'] = $post_dealseq;
$parametersArray['uid'] = $post_uid;
$parametersArray['subject'] = $post_subject;
$parametersArray['v'] = $post_v;

ksort($parametersArray);

$sourcestr="";
foreach ($parametersArray as $key => $val) {

$sourcestr==""?$sourcestr=$key."=".$val:$sourcestr.="&".$key."=".$val;
}


$log->info($date." Raw sign is: ".$sourcestr);

//对数据进行验签,注意对公钥做格式转换
$publicKey = Rsa::instance()->convert_publicKey($publicKey);
//$verify = Rsa::instance()->verify($sourcestr, $post_sign, $publicKey);

$log->info($date." Verification result is ".$verify);

/*if($verify!=1){
$log->warn($date." Failed to verify data");
return "failed";
}*/

//对加密的notify_data进行解密
$post_notify_data_decode = base64_decode($post_notify_data);

$decode_notify_data = Rsa::instance()->publickey_decodeing($post_notify_data_decode, $publicKey);

$log->info($date." Notify data decoded as ".$decode_notify_data);

parse_str($decode_notify_data);

$log->info($date." dealseq: ".$dealseq." fee: ".$fee." payresult: ".$payresult);

//比较解密出的数据中的dealseq和参数中的dealseq是否一致
if($dealseq==$post_dealseq){
$log->info($date." Success");
//TODO:开发商根据dealseq将支付结果记录下来,并根据支付结果做相应处理
return $decode_notify_data;
//return "success";
}else{
$log->warn($date." Dealseq values did not match");
return "failed";
}
}
?>

[b]异常信息:[/b]
异常详细信息: System.Xml.XmlException: 根级别上的数据无效。 第 1 行,位置 1。
源错误:
行 45: [return: System.Xml.Serialization.SoapElementAttribute("return")]
行 46: public string verify_data(string public_Key, string post_sign, string post_notify_data, string post_orderid, string post_dealseq, string post_uid, string post_subject, string post_v) {
行 47: object[] results = this.Invoke("verify_data", new object[] {
行 48: public_Key,
行 49: post_sign,

堆栈跟踪:
[XmlException: 根级别上的数据无效。 第 1 行,位置 1。]
System.Xml.XmlTextReaderImpl.Throw(Exception e) +69
System.Xml.XmlTextReaderImpl.Throw(String res, String arg) +116
System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace() +5573303
System.Xml.XmlTextReaderImpl.ParseDocumentContent() +347
System.Xml.XmlTextReaderImpl.Read() +213
System.Xml.XmlTextReader.Read() +13
System.Xml.XmlReader.MoveToContent() +70
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) +479
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +215

[InvalidOperationException: 响应不是格式正确的 XML。]
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +296
WebService.decryptWSDLtest.verify_data(String public_Key, String post_sign, String post_notify_data, String post_orderid, String post_dealseq, String post_uid, String post_subject, String post_v) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\website1\109189c2\8bc12de5\App_WebReferences.ff3fraia.0.cs:47
PhpWebService.insertData(String post_notify_data, String post_orderid, String post_dealseq, String post_uid, String post_subject, String post_v, String post_sign) in f:\dingl\WebSite1\PhpWebService.aspx.cs:118
PhpWebService.Button1_Click(Object sender, EventArgs e) in f:\dingl\WebSite1\PhpWebService.aspx.cs:91
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9752490
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +196
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

各位大侠,帮忙看下,为什么.net端调用php中的verify_data方法总报这个错?该怎么解决啊?急!!!
...全文
1085 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
风之影子 2014-05-31
  • 打赏
  • 举报
回复
这个可以肯定的是你的XML没有正确解析,用测试工作看看返回来的XML是否正常。 或者用环境断点提取XML原文看看。
abcde760 2014-04-30
  • 打赏
  • 举报
回复
顶顶顶顶!!
abcde760 2014-04-29
  • 打赏
  • 举报
回复
没人么?大家帮帮忙,看看嘛

12,163

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧