WebService调用1(.Net)
1.创建一个最简单的Web Service
(1) 新建-项目-ASP.NET空WEB应用程序
(2)添加新项-WEB服务
默认会添加一个HelloWorld方法:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services; namespace MyNetWebService
{
/// <summary>
/// MyWebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
// [System.Web.Script.Services.ScriptService]
public class MyWebService : System.Web.Services.WebService
{ [WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
右击在浏览器中查看:

可以接着点击HelloWorld方法->点击调用。
2.WebService 调用
2.1调用webserivice 最简单的方法就是在 "引用" 那里点击右键,然后选择"引用web服务",再输入服务地址。
确定后,会生成一个app.config 里面就会自动生成了一些配置信息。
用ASP.NET调用Web Service
新建网站后 右击添加新项 发现VS2014没有”添加WEB引用“项,几经周折发现在”添加服务引用“—>”高级“—>”添加WEB引用“
在URL中填入,前面写好的WebService运行后浏览器上面显示的地址,点击“前往”按钮,如上图,就会显示出所引用的WebService中可以调用的方法,然后点击“添加引用”,就将webservice引用到了当前的工程里面 ,如下图,解决方案中会出现引进来的WebService文件

在此练习调用webservice的HelloWorld方法:在前台添加两个控件
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CallWebService.aspx.cs" Inherits="CallWebService" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>"引用web服务"方式调用WebService</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="show" runat="server" ></asp:Label>
<asp:Button ID="btn" runat="server" Text="Show" OnClick="btn_Click" />
</div>
</form>
</body>
</html>
在后台写调用WebService的代码,调用之前和使用其他的对象一样,先要实例化。运行后看到显示效果,而整个过程并不是在本地进行的,是在Web服务端进行计算然后将结果通过XML返还还给调用方法的,所以,在运行该程序的时候,WebService程序还必须启动,否则会报无法连接远程服务器的异常。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class CallWebService : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void btn_Click(object sender, EventArgs e)
{
//实例化WebService对象
NetWebService.MyWebService webservice = new NetWebService.MyWebService();
//通过实例化的webservice对象来调用Webservice暴露的方法
show.Text = webservice.HelloWorld();
}
}
WebService调用1(.Net)的更多相关文章
- 使用自定义签名的https的ssl安全问题解决和metro的webservice调用
最近一直在忙新的项目,每天加班到8点多,都没来写博客了.新的项目遇到了很多问题,现在趁着突然停电来记录下调用https的问题吧. 我们服务主要是,我们调用数据源数据,并且再提供接口供外部数据调用. 我 ...
- C#动态webservice调用接口 (JAVA,C#)
C#动态webservice调用接口 using System; using System.Collections; using System.IO; using System.Net; using ...
- WebService 调用
一.WebService调用 1.webservice支持四种调用方式:SOAP 1.1,SOAP 1.2,GET,POST. 2.如果要webservice支持GET,POST调 ...
- 使用XmlInclude解决WebService调用时无法识别子类的异常
一.定义抽象类及子类,WebMethod实际返回子类参数 //使用XmlInclude解决WebService调用时无法识别子类的异常 [System.Xml.Serialization.XmlInc ...
- WebService调用一对多关联关系时出现 死循环:A cycle is detected in...
通过WebService调用一对多关联关系时引起的问题:A cycle is detected in the object graph 具体异常信息: org.apache.cxf.intercept ...
- C# ASP.NET Webservice调用外部exe无效的解决方法
最近用asp.net做webservice,其中有个功能是调用执行外部的exe(类似cmd中执行),但执行Process.Start之后就没有结果,同样代码在winform下正常,折腾两天终于找到解决 ...
- 【技术贴】webservice 调用 Transport error : 401 Error:Una
解决 webservice 调用之后报错:调用异常:Transport error : 401 Error:Unauthorized 授权失败. 加入如下代码 //Sap需要ws-security的认 ...
- [置顶] WebService调用工具(AXIS2)
package com.metarnet.util; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Meth ...
- WebService 调用三种方法
//来源:http://www.cnblogs.com/eagle1986/archive/2012/09/03/2669699.html 最近做一个项目,由于是在别人框架里开发app,导致了很多限制 ...
随机推荐
- HTML - Textarea - 空格的问题解决方式
第一种方式: <textarea name="textareaname" rows="XX" cols="XX" ></t ...
- html进阶css(2)
选择器的类型 <!doctype html> <html> <head> <meta charset="utf-8"> <ti ...
- Qt Library 链接库
官方教程:http://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application http://qimo601.i ...
- makefile 单独编译一个文件
#!/sh/bin .SUFFIXES:.c.o CDIR = /Users/shelley/c BINDIR = $(CDIR)/bin CC = gcc CFLAGS = -g -O RM = r ...
- nginx+keepalived+tomcat之具体配置档
前沿知识点: nginx负责负载均衡(反向代理) msm(memcached session manager)负责缓存会话信息,从而实现会话保持 所需包: nginx和memcached采用最新稳定版 ...
- innobackupex 使用说明
1.创建备份相关用户 '; grant reload,lock tables,replication client,process,super on *.* to 'backuper'@'127.0. ...
- git diff 使用
1. 本地工作目录与远程仓库对比(所有改动过的文件) git diff HEAD (HEAD指向最新一次的提交,即最新版本) 2. 之对比给定的文件 git diff -- filename //是 ...
- cf478C Table Decorations
C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Word Ladder 解答
Question Given two words (beginWord and endWord), and a dictionary's word list, find the length of s ...
- (转)ZOJ 3687 The Review Plan I(禁为排列)
The Review Plan I Time Limit: 5 Seconds Memory Limit: 65536 KB Michael takes the Discrete Mathe ...