问一个调用webservice的问题

ying1234 2005-01-14 02:26:46
databaseservice.asmx代码:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace Webservice2
{
/// <summary>
/// databaseservice 的摘要说明。
/// </summary>
public class databaseservice : System.Web.Services.WebService
{
protected OleDbConnection conn;
protected OleDbDataAdapter adapter;
protected string connStr;
protected string sqls;
protected DataSet dataSet;
protected string result;
public databaseservice()
{
//CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
InitializeComponent();
}

#region 组件设计器生成的代码

//Web 服务设计器所必需的
private IContainer components = null;

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{

}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion

// WEB 服务示例
// HelloWorld() 示例服务返回字符串 Hello World
// 若要生成,请取消注释下列行,然后保存并生成项目
// 若要测试此 Web 服务,请按 F5 键

[WebMethod]
public DataSet ViewDB(string name,string pwd)
{
if(name=="shilei" && pwd=="shileiisadog")
{
connStr="Provider=SQLOLEDB;uid=sa;pwd=;server=ying;database=shili";
conn=new OleDbConnection(connStr);
sqls="select 身份证号码,员工姓名,员工性别,家庭住址 from 临时人员 order by 身份证号码";
adapter=new OleDbDataAdapter();
adapter.SelectCommand=new OleDbCommand(sqls,conn);
dataSet=new DataSet();
adapter.Fill(dataSet,"临时人员");
conn.Close();
return dataSet;
//result="通过验证,你可以读取数据库";
}
else
//result="错误的用户名或密码!";
return dataSet;

}
}
}
asp调用代码:
<html>
<head>
<title>client</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<%
Set objHTTP = Server.CreateObject("MSXML2.XMLHTTP")
Set xmlDOC =Server.CreateObject("MSXML.DOMDocument")
strWebserviceURL = "http://localhost/WebService2/databaseservice.asmx/add"
'设置参数及其值 <BR>'
strRequest = "name=shilei" & "pwd=shileiisadog"

objHTTP.Open "POST", strWebserviceURL, False
'设置这个Content-Type很重要
objHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objHTTP.Send(strRequest)
bOK = xmlDOC.load(objHTTP.responseXML)
'看看状态值
if objHTTP.Status=200 then
xmlStr = xmlDOC.xml
xmlStr = Replace(xmlStr,"<","<",1,-1,1)
xmlStr = Replace(xmlStr,">",">",1,-1,1)
Response.Write xmlStr
else
Response.Write objHTTP.Status&"<br>"
Response.Write objHTTP.StatusText
end if
%>


<body>


</body>
</html>

运行后结果:
500
鍐呴儴鏈嶅姟鍣ㄩ敊璇€? Server: Microsoft-IIS/5.0

这不是我想调用表的内容。请问高手们该怎么解决?
另外
strRequest = "name=shilei" & "pwd=shileiisadog" 这句话我不明白,难道连方法名都不用指定就可
以调用了吗?
要是我有二个服务,都接收二个字符串参数,我怎么知道是调用哪个服务?
...全文
102 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ying1234 2005-01-14
  • 打赏
  • 举报
回复
xjking0331(Michael J
strWebserviceURL = "http://localhost/WebService2/databaseservice.asmx/ViewDB?name=shilei&pwd=shileiisadog"
加了还是出现同样的结果。
xjking0331 2005-01-14
  • 打赏
  • 举报
回复
好像要
strWebserviceURL = "http://localhost/WebService2/databaseservice.asmx/ViewDB?name=shilei&pwd=shileiisadog"
tengjian1981 2005-01-14
  • 打赏
  • 举报
回复
up

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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