.NET 创建 WebService
服务器端代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Xml.Serialization;
using System.Web.Services.Protocols;
using System.IO;
using System.Xml; namespace WebService1
{
/// <summary>
/// Service1 的摘要说明
/// </summary> [WebService(
Namespace = "http://asn.test.cn/",
Description="this is a test service!")]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{ [WebMethod]
[SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Wrapped)]
public void PurchaseOrder(
[XmlAttribute] String ID,
DateTime Date,
int Amount,
out String ReceiptID)
{
ReceiptID = "";
return;
} [WebMethod]
[return: XmlElement("PurchaseOrderRecipt")]
[SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare, OneWay = true)]
public void PurchaseOrderStyleBare(PO pOrder)
{
FileStream fileStream = new FileStream("c:/aa.txt",FileMode.Append ,FileAccess.Write);
StreamWriter writer = new StreamWriter(fileStream);
writer.WriteLine(pOrder.ID);
writer.WriteLine(pOrder.Date.ToString());
writer.Close();
return ;
} [WebMethod]
[SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Wrapped)]
public double Divide(double x, double y)
{
if (y == )
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<BadStuff>you shouldn't try to divide by zero. </BadStuff>");
XmlQualifiedName code = new XmlQualifiedName("Sample", "http://sample");
SoapException ex = new SoapException("Can not divide by zero", code, "TheActor", doc); throw ex;
}
return x / y;
}
}
}
客户端调用代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceClient.ServiceTest;
using System.Web.Services;
using System.Xml.Serialization;
using System.Web.Services.Protocols; namespace ServiceClient
{
class Program
{
static void Main(string[] args)
{ Service1SoapClient server = new Service1SoapClient();
double resl = server.Divide(, );
Console.WriteLine(resl); ServiceTestClient client = new ServiceTestClient();
double resl1 = client.Divide(, );
Console.WriteLine(resl1);
}
} [WebServiceBinding("Service1Soap", "http://asn.test.cn/")]
public class ServiceTestClient : SoapHttpClientProtocol
{
public ServiceTestClient()
{
this.Url = "http://localhost:49559/Service1.asmx";
} [SoapDocumentMethod("http://asn.test.cn/Divide"]
public double Divide(double x, double y)
{
Object[] args = { x, y};
Object[] responseMsg = this.Invoke("Divide", args); return (double)responseMsg[];
}
}
}
.NET 创建 WebService的更多相关文章
- 利用JDK(1.6及以上版本)创建WebService
一.什么是WebService WebService是一个SOA(面向服务的编程)的架构,它是不依赖于语言,不依赖于平台,可以实现不同的语言间的相互调用,通过Internet进行基于Http协议的网络 ...
- 如何使用C#创建WebService
使用C#创建WebService,服务端的webservice是必须,中间的soap,Xml我们不用去关心.下面是使用C#创建WebService的简单介绍. AD:51CTO技术沙龙 | 赋予APP ...
- 【转】SoapUI5.0创建WebService接口模拟服务端
原文:http://blog.csdn.net/a19881029/article/details/26348627 使用SoapUI创建WebService接口模拟服务端需要接口描述文件 MathU ...
- MyEclipse创建WebService
使用Eclipse的话还要装web tool platform很多东西,用MyEclipse一步到位,创建WebService很方便. MyEclipse中有自己的Tomcat,要把事先在电脑上独立安 ...
- 【转】vs2010下创建webservice
题记:学了六个月java一直想做java,没想到进了.NET项目组,还是VB2012,还有WebService,压力山大,这篇纯粹看看多图的效果,版主不要怪罪. Visual Studio 2010默 ...
- 一个php创建webservice,并通过c#调用的真实实例
最近需要用php创建webservice供C#和JAVA来调用,通过3天的搜索和尝试,终于成功在C#下调用,JAVA的调用还没开始,为防止忘记,在这里记录下来全过程. 本文参考了许多文章,文中也采用了 ...
- gsoap创建webservice服务简单教程
版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] WebServicesoapgsoap 使用gsoap创建webservice服务 下载gsop 准备待导出的服务接口定义文件比 ...
- 根据wsdl文件用soapUi快速创建webService服务(有图有真相)
最近公司业务上使用webservice 频繁.由于之前都是自己搭建webservice 自己定义提供给别人服务,现在则相反需求都是根据人家提供的wsdl 文件来生成 我们平台需要提供的接口.刚开始不知 ...
- java(MyEclipse)创建webservice和测试webservice
转载地址:http://blog.csdn.net/hsfy2012/article/details/46300921 创建并发布自己的Webservice的工具 1 安装MyEclipse 2 ...
- Axis创建webservice客户端和服务端
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本人声明.否则将追究法律责任. 作者:永恒の_☆ 地址:http://blog.csdn.net/chenghui0317/ ...
随机推荐
- SQL Server2008 卸载
先把SQL Server卸载,再把安装时产生的“Microsoft SQL Server”文件夹删掉,在运行注册表,把HKEY_CURRENT_USER\Software\Microsoft\Micr ...
- day38 19-Spring整合web开发
整合Spring开发环境只需要引入spring-web-3.2.0.RELEASE.jar这个jar包就可以了,因为它已经帮我们做好了. Spring整合web开发,不用每次都加载Spring环境了. ...
- R是用于统计分析、绘图的语言和操作环境
R是一套完整的数据处理.计算和制图软件系统.其功能包括:数据存储和处理系统:数组运算工具(其向量.矩阵运算方面功能尤其强大):完整连贯的统计分析工具:优秀的统计制图功能:简便而强大的编程语言:可操纵数 ...
- laravel之文件上传
laravel框架中的文件上传我们应该如何实现此功能呢? 之前也是没有使用过laravel的文件上传功能,后来在网上找到一些教程,五花八门.让我看起来有点头疼. 有时候找到测试浪费好长时间最后还是出不 ...
- GeoServer手动发布本地Shapefile地图
首先,本文实现的结果图给大家展现一下: 放大的样子: 颜色是通过属性中某个字段值来分级的,可以自定义. 上面功能是用ArcGIS切片好数据,在Geoserver 中发布,并用google地图作为底图展 ...
- SiteMesh:一个优于Apache Tiles的Web页面布局、装饰框架
一.SiteMesh项目简介 OS(OpenSymphony)的SiteMesh是一个用来在JSP中实现页面布局和装饰(layout and decoration)的框架组件,能够帮助网站开发人员较容 ...
- 操作系统之LRU算法 C语言链表实现
LRU是Least Recently Used的缩写,即最近最少使用,是一种常用的页面置换算法,选择最近最久未使用的页面予以淘汰.该算法赋予每个页面一个访问字段,用来记录一个页面自上次被访问以来所经历 ...
- poj3422 最小费用流
一遍的话秩序要dp就好,但是这里要删去点.此题可以转化为最小费用流.开始我想了半天纠结怎么处理到过一次后值变0,看了书之后发现拆点解决了这个问题. 对于点t,拆为t-->t',容量为1,费用为负 ...
- PLAY2.6-SCALA(四) 请求体解析器
一个http请求是一个请求头后面跟着一个请求体,头部信息比较短,可以安全的缓存在内存中,在Play中头部信息使用RequestHeader类进行建模.请求体的内容可能较大,使用流stream的形式进行 ...
- 前端规范1-HTML规范
HTML规范 1代码风格(参1,) 使用Tab字符(四个空格长度) 层级关系太多时尽量写在一行,但保证每行代码不宜过长 例,代码不宜过长 例,尽量写在一行 2命名(参1,) class必须使用小写, ...