C#的WEB SERVICES程序如下:public class Service1 : System.Web.Services.WebService
{
public Service1()
{
//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 string getString(string str)
{
return "Hello World " + str;
} }
VB写的调用的程序代码如下: 里面有三个控件:TEXT1(输出结果),TEXT2(输入字符),COMMAND1
Private Sub Command1_Click()
Dim strxml As String
Dim str As String
str = Text2.Text
'定义soap消息
strxml = "<?xml version='1.0' encoding='utf-8'?>"
strxml = strxml + "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"
strxml = strxml + "<soap:Body>"
strxml = strxml + "<getString xmlns='http://tempuri.org/'><str>" & str & "</str></getString>"
strxml = strxml + "</soap:Body>"
strxml = strxml + "</soap:Envelope>"
'定义一个http对象,一边向服务器发送post消息
Dim h As MSXML2.ServerXMLHTTP40
'定义一个XML的文档对象,将手写的或者接受的XML内容转换成XML对象
Dim x As MSXML2.DOMDocument40
'初始化XML对象
Set x = New MSXML2.DOMDocument40
'将手写的SOAP字符串转换为XML对象
x.loadXML strxml
'初始化http对象
Set h = New MSXML2.ServerXMLHTTP40
'向指定的URL发送Post消息
h.open "POST", "http://localhost/WebService1/Service1.asmx", False
h.setRequestHeader "Content-Type", "text/xml"
h.send (strxml)
While h.readyState <> 4
Wend
'显示返回的XML信息
Text1.Text = h.responseText
'将返回的XML信息解析并且显示返回值
Set x = New MSXML2.DOMDocument40
x.loadXML Text1.Text
Text1.Text = x.childNodes(1).TextEnd Sub返回的错误信息是:soap:Client System.Web.Services.Protocols.SoapException: 没有有效的操作参数,无法处理请求。请提供有效的 SOAP 操作。
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
{
public Service1()
{
//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 string getString(string str)
{
return "Hello World " + str;
} }
VB写的调用的程序代码如下: 里面有三个控件:TEXT1(输出结果),TEXT2(输入字符),COMMAND1
Private Sub Command1_Click()
Dim strxml As String
Dim str As String
str = Text2.Text
'定义soap消息
strxml = "<?xml version='1.0' encoding='utf-8'?>"
strxml = strxml + "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"
strxml = strxml + "<soap:Body>"
strxml = strxml + "<getString xmlns='http://tempuri.org/'><str>" & str & "</str></getString>"
strxml = strxml + "</soap:Body>"
strxml = strxml + "</soap:Envelope>"
'定义一个http对象,一边向服务器发送post消息
Dim h As MSXML2.ServerXMLHTTP40
'定义一个XML的文档对象,将手写的或者接受的XML内容转换成XML对象
Dim x As MSXML2.DOMDocument40
'初始化XML对象
Set x = New MSXML2.DOMDocument40
'将手写的SOAP字符串转换为XML对象
x.loadXML strxml
'初始化http对象
Set h = New MSXML2.ServerXMLHTTP40
'向指定的URL发送Post消息
h.open "POST", "http://localhost/WebService1/Service1.asmx", False
h.setRequestHeader "Content-Type", "text/xml"
h.send (strxml)
While h.readyState <> 4
Wend
'显示返回的XML信息
Text1.Text = h.responseText
'将返回的XML信息解析并且显示返回值
Set x = New MSXML2.DOMDocument40
x.loadXML Text1.Text
Text1.Text = x.childNodes(1).TextEnd Sub返回的错误信息是:soap:Client System.Web.Services.Protocols.SoapException: 没有有效的操作参数,无法处理请求。请提供有效的 SOAP 操作。
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货