.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/ ...
随机推荐
- LintCode刷题笔记-- Distinct Subsequences
标签:动态规划 题目描述: Given a string S and a string T, count the number of distinct subsequences of T in S. ...
- ecshop二次开发之后台秒杀
1.进入admin->includes->inc_menu.PHP中此文件为定义左侧功能模块超链接 2.添加include/inc_menu.php秒杀管理超链接找链接 $modules[ ...
- 【JZOJ5064】【GDOI2017第二轮模拟day2】友好城市 Kosarajo算法+bitset+ST表+分块
题面 在Byteland 一共有n 座城市,编号依次为1 到n,这些城市之间通过m 条单向公路连接. 对于两座不同的城市a 和b,如果a 能通过这些单向道路直接或间接到达b,且b 也能如此到达a,那么 ...
- js中小知识点
JavaScript 中 typeof 和 instanceof 常用来判断一个变量是否为空,或者是什么类型的.但它们之间还是有区别的: typeof typeof 是一个一元运算,放在一个运算数之前 ...
- oracle如何限定特定IP访问数据库
可以利用登录触发器.cmgw或者是在$OREACLE_HOME/network/admin下新增一个protocol.ora文件(有些os可能是. protocol.ora),9i可以直接修改sqln ...
- Codeforces 425B
点击打开题目链接 题意:给定一个n×m的0,1矩阵,做多可以对矩阵做k次变换,每次变换只可以将矩阵的某一个元素由0变成1,或从1变成0. 求最小的变换次数使得得到的矩阵满足:每一个连通块都是一个“实心 ...
- 1.Golang开山篇,GO就是NB!
目录:GO就是NB GO sb吗 安装环境 GO就是NB,K2R三位大佬写的GO,学GO不吃亏! (1)我们为什么要学 高并发 深度 || 广度 (2)go学习思路和目标 多打多练 掌握go语言 做一 ...
- OpenJudge_1936:All in All
描述 You have devised a new encryption technique which encodes a message by inserting between its char ...
- iOS如何才能在招聘中表现得靠谱?
http://www.cocoachina.com/programmer/20150707/12414.html 近一年内陆续面试了不少人了,从面试者到面试官的转变让我对 iOS 招聘有了更多的感受. ...
- 【批量添加】-拼接sql字符串 标签: 批量添加 2015-12-13 17:49 2070人阅读 评论(33)
现在做的一个项目需要用到批量添加,但是封装的底层没有这个方法,所以自食其力,自己来写.我们用的是拼接sql字符串的方法来实现功能. 具体实现流程:首先将需要的数据存储到实体的list中,然后将这个li ...