- 爱易网页
-
PHP教程
- php怎么调用.net的webservice?100分送上
日期:2014-05-17 浏览次数:20652 次
php如何调用.net的webservice???100分送上
php如何调用.net的webservice?请高手赐教,我写了一面一段程序,可是总是提示错误:没有创建实例对象,大家帮我看一下,哪里错了?
客户端php程序:
<?php
require('./require/nusoap/lib/nusoap.php');
$userinfo=array('username' => 'fiekscos');
$s=new soapclient('http://www.yy-sports.com/webservice/memberinfo.asmx?WSDL');
$s->soap_defencoding = 'UTF-8';
$s->decode_utf8 = false;
$result = $s->__soapCall('ValidUserLoginName',array('UserLoginName' => $userinfo));
echo $result;
?>
服务器端.net的webservice程序:
using System;
using System.Collections;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using com.Basic;
/// <summary>
///MemberInfo 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class MemberInfo : System.Web.Services.WebService
{
// <summary>
/// SOAP认证类
/// </summary>
public SecurityHeader CurrentUser
{
get { return _CurrentUser; }
set { _CurrentUser = value; }
}
private SecurityHeader _CurrentUser;
public MemberInfo()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
private bool ValidateUser(string user, string pass)
{
Boolean reVal=false;
EDbOperator oo = new EDbOperator();
try
{
String sql = "Select Count([ID]) From WebService_User Where [Name]='{0}' And Pass='{1}' And [Status] = 1";
user = Tools.FilterSQL(user.Trim());
pass = Tools.FilterSQL(pass.Trim());
sql = String.Format(sql, user, pass);
Int32 Count = Convert.ToInt32(oo.DbOperator.ExecScalar(sql));
if (Count > 0)
{
reVal = true;
}
}
finally
{
oo.Dispose();
}
return reVal;
}
/// <summary>
/// 根据系列代码,返回系列名称
/// </summary>
/// <param name="SeriesCode">系列代码</param>
/// <returns>系列名称</returns>
[WebMethod(Description = "输入一个新的用户登录名称,判断是否已经注册 0为未注册 非0为已注册或出错"), SoapHeader("CurrentUser")]
public Int32 ValidUserLoginName(String UserLoginName)
{
if (!ValidateUser(CurrentUser.UserName, CurrentUser.UserPass)) { throw new Exception("出错"); }
Int32 reVal = 1;
EDbOperator oo = new EDbOperator();
try
{
String sql;
sql = "Select Count([ID]) From YY_User Where [UserName] = '" + UserLoginName + "'";
reVal = Convert.ToInt32(oo.DbOperator.ExecScalar(sql));
}
finally
{
oo.Dispose();
}
return reVal;
}
}
//自定义Soap Header Class
public class SecurityHeader : System.Web.Services.Protocols.SoapHeader
{
public String UserName;
public String UserPass;