[WebMethod]
public string HelloStr(string name)
{
return "Hello "+name;
}
|
WebTest.Service1 webtest=new WSApplication.WebTest.Service1();
//生成一个新的调用服务类型
NetworkCredential credential=new NetworkCredential("test","test001"," ");
webtest.Credentials=credential; //带上身份验证信息
string ret=webtest.HelloStr("张三");
MessageBox.Show(ret);
|
注意:这样的调用方式只适合Windows系统,即调用服务者必须是Windows系统;如果是UNIX系统,则不会成功。 |
[SoapHeader("myHeader")]
[WebMethod]
public string HelloWorld()
{
return "hello :"+myHeader.UserID+myHeader.UserPW;
}
public class MyHeader: System.Web.Services.Protocols.SoapHeader
{
private string _UserID=string.Empty; //用户名
private string _UserPW=string.Empty; //用户密码
public MyHeader()
{
public string UserID
{
get{return _UserID;}
set{_UserID=value;}
}
public string UserPW
{
get{return _UserPW;}
set{_UserPW=value;}
}
}
|
private void menuItem4_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Soap头测试实验!");
string ret;
SoapHeader.MyHeader myHeader=new WSApplication.SoapHeader. MyHeader();
myHeader.UserID="yanxuexiong";
myHeader.UserPW="zhangqiao";
SoapHeader.SoapHeader headertest=new WSApplication.SoapHeader.
SoapHeader();
headertest.MyHeaderValue=myHeader;
ret=headertest.HelloWorld();
MessageBox.Show(ret);
}
|
//添加的自己的SOAP头结构
public class SoapHeader1 :System.Web.Services.Protocols.SoapHeader
{
public string UserID;
public string PassWord;
}
|
public SoapHeader1 soapheader1; //手工加上的SOAP头 |
[System.Web.Services.Protocols.SoapHeaderAttribute("soapheader1")]
//添加头的声明
|
//-------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version: 1.1.4322.2032
//
// Changes to this file may cause incorrect behavior and will be lost
// if the code is regenerated.
// </autogenerated>
//-------------------------------------------------------------------
//
// 此源代码是由 Microsoft.VSDesigner 1.1.4322.2032 版自动生成
//
namespace WSApplication.SoapTest2 {
using System.Diagnostics;
using System.Xml.Serialization;
using System;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Web.Services;
/// <remarks/>
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="Service1Soap", Namespace="http://tempuri.org/")]
public class Service1:System.Web.Services.Protocols.SoapHttpClientProtocol{
public SoapHeader1 soapheader1; //手工添加的SOAP头
/// <remarks/>
public Service1() {
this.Url = "http://192.192.192.73/WSSoapTest2/SoapHeaderTest2. asmx";
}
/// <remarks/>
///
[System.Web.Services.Protocols.SoapHeaderAttribute("soapheader1")] //添加的头声明
[System.Web.Services.Protocols.SoapDocumentMethodAttribute ("http://tempuri.org/HelloWorld", RequestNamespace="http:// tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System. Web.Services.Description. SoapBindingUse.Literal, ParameterStyle= System.Web.Services.Protocols. SoapParameterStyle.Wrapped)]
public string HelloWorld() {
object[] results = this.Invoke("HelloWorld", new object[0]);
return ((string)(results[0]));
}
/// <remarks/>
public System.IAsyncResult BeginHelloWorld(System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("HelloWorld", new object[0], callback, asyncState);
}
/// <remarks/>
public string EndHelloWorld(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((string)(results[0]));
}
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http:// www.w3.org/2001/XMLSchema">
<soap:Header>
<SoapHeader1 xmlns="http://tempuri.org/">
<UserID>yanxuexiong</UserID>
<PassWord>zhangqiao</PassWord>
</SoapHeader1>
</soap:Header>
<soap:Body>
<HelloWorld xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
| 回书目 上一节 下一节 |
|
· 第六章 你能帮我吗?.. · Linux笔试面试题选摘测.. · 08年5月软考网管上午真.. · 性能测试从零开始 目录 · 08年5月软考网工上午真.. · 上周拒绝服务攻击(DDo.. |
· 08年5月各大网上书店及.. · 2008年5月24日软考试题.. · 软件设计师专家临考模.. · 上周网络管理员专家自.. · 网络工程师自测获奖名.. · 08年4月各大网上书店及.. |
|
||||
| · NAC安全访问控制 · 网络布线测试仪器 · Windows Server 2008专.. · Windows远程桌面应用 · 网络故障排除宝典 · 运营商封堵ADSL共享 中.. · 解析35岁技术人的价值.. · 世纪枭雄比尔盖茨的王.. |
· 主流品牌防火墙配置 · ASP.NET开发教程 · 超级计算机TOP500专题 · Vista SP1对决XP SP3 · SQL Server 2008/2005.. · 程序员如何成长? · C#技术开发指南 · 虚拟化技术还有点“虚” |
|||
|
||||
| · SOA 面向服务架构 · SQL Server 2008/2005.. · Apache技术专题 · 三层交换技术专题 · SQL Server入门到精通 · Windows远程桌面应用 · C#技术开发指南 · Apache技术专题 |
· Windows集群服务应用 · C#技术开发指南 · 国际文档格式标准开战 · 路由器设置与口令恢复 · Linux 集群技术专题 · PHP开发应用手册 · SOA 面向服务架构 · 企业数据恢复指南 |
|||
|
||||
| · SQL Server入门到精通 · SQL Server 2008/2005.. · SOA 面向服务架构 · Apache技术专题 · C#技术开发指南 · 三层交换技术专题 · Apache技术专题 · C#技术开发指南 |
· Windows远程桌面应用 · 企业数据恢复指南 · Windows集群服务应用 · 路由器设置与口令恢复 · Linux 集群技术专题 · SOA 面向服务架构 · 了解统一威胁管理(UTM).. · 反垃圾邮件技术应用 |
|||