Azure开发者任务之六:使用WCF Service Web Role
在本文中,我们将会在local development fabric上创建一个WCF服务角色,然后在一个控制台应用程序中使用它。
WCF服务角色可以让我们创建一个WCF服务,并且把它托管在Windows Azure中。在本文中,我们将会创建一个WCF服务角色,把它托管在local development fabric上,然后在一个控制台应用程序中使用它。在下一篇文章中,我们将会把这个WCF服务迁移到Azure门户中。
首先
1,创建一个新项目
2,导航到“Cloud”标签
3,创建Windows Azure项目
4,在给出的选项中选择WCF服务角色

如果你看一下解决方案资源管理器,你会发现这个WCF服务角色项目的结构和文件与正常创建的WCF服务应用程序完全相同。它包含:
1,IService1.cs(服务契约)
2,Service1.svc.cs(服务定义)
3,Web.config(EndPoint的配置)
我们可以按照我们的需求来修改这些文件,这和我们平时在一个WCF服务应用程序中做的事情没有什么两样。
让我们来修改服务契约:
IService1.svc
using System.ServiceModel;
namespace WCFServiceWebRole1
{
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
}
}
然后,修改服务定义:
Service1.svc.cs
namespace WCFServiceWebRole1
{
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
}
在Web.Config中保留默认的配置。
确保你已经把Windows Azure项目设置成启动项目了,然后运行这个应用程序。在浏览器中,你会得到如下错误信息:

忽略这个错误信息,然后把一个URL添加到“Service1.svc”中,这个URL应该是http://127.0.0.1:81/Service1.svc。“Service1.svc”是服务定义的名字。添加以后,你会在浏览器中得到通常的WCF服务消息

要在一个控制台客户端中测试这个WCF服务角色,需要:
1,创建一个控制台应用程序项目
2,使用指定的URL(http://127.0.0.1:81/Service1.svc)来添加服务引用

现在,我们编写一个正常的服务调用:
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConsoleApplication14.ServiceReference1;
namespace ConsoleApplication14
{
class Program
{
static void Main(string[] args)
{
Service1Client proxy = new Service1Client();
var result = proxy.GetData(99);
Console.WriteLine(result);
Console.ReadKey(true);
}
}
}
现在,当你运行这个应用程序的时候,你也许会得到下面这个异常:

要解决上面这个异常,我们必须要编辑“App.Config”文件。我们需要修改这个配置文件:

“127.0.0.1”代表“localhost”。也许这个控制台应用程序不能解析“127.0.0.1”,所以,我们把它改成“localhost”:

现在,运行这个应用程序,我们会得到如下输出:

这里,我们需要注意的一个行为是,有时,在把“127.0.0.1”改成“localhost”以后,你可能还是会得到那个超时异常。在我以后的文章中,我会深入研究一下这个意料之外的行为。
原文名:Windows Azure for Developers Task 8: Working with WCF Service Web Role 作者: Dhananjay Kumar
Azure开发者任务之六:使用WCF Service Web Role的更多相关文章
- Azure开发者任务之七:在Azure托管服务中托管WCF服务角色
在一个托管服务中托管一个WCF服务角色和托管一个ASP.Net Web Role基本类似. 在上一篇文章中,我们学习了如何使用WCF Service Web Role. 在本文中,我会对上一篇文章进行 ...
- Azure开发者任务之三:理解Azure应用程序(上)
作为Windows Azure的托管服务被设计和开发的应用程序由这两部分组成: 1,托管代码 2,XML配置文件 托管代码对应不同的角色 XML文件对应不同的配置设置 我们可以看一下下面这张图,它详细 ...
- [Windows Azure] Building the web role for the Windows Azure Email Service application - 3 of 5
Building the web role for the Windows Azure Email Service application - 3 of 5. This is the third tu ...
- Azure开发者任务之二:Cloud Service项目添加到ASP.Net Web中
假设我们正在把现有的Web应用程序或ASP.Net MVC Web应用程序迁移到云中.在这种情况下,我们需要把云服务添加到现有的Web应用程序或ASP.Net MVC Web应用程序中. 我们有一个W ...
- wcf和web service的区别
1.WebService:严格来说是行业标准,不是技术,使用XML扩展标记语言来表示数据(这个是夸语言和平台的关键).微软的Web服务实现称为ASP.NET Web Service.它使用Soap简单 ...
- WCF和Web Service的 区(guan)别(xi)
参考文献:http://social.microsoft.com/Forums/zh-CN/c06420d1-69ba-4aa6-abe5-242e3213b68f/wcf-webservice 之前 ...
- WCF、Web API、WCF REST、Web Service比较
原文地址:http://www.dotnet-tricks.com/Tutorial/webapi/JI2X050413-Difference-between-WCF-and-Web-API-and- ...
- Difference between WCF and Web API and WCF REST and Web Service
The .Net framework has a number of technologies that allow you to create HTTP services such as Web S ...
- WCF 、Web API 、 WCF REST 和 Web Service 的区别
WCF .Web API . WCF REST 和 Web Service 的区别 The .Net framework has a number of technologies that allow ...
随机推荐
- 不停止MySQL服务增加从库的两种方式
不停止MySQL服务增加从库的两种方式 转载自:http://lizhenliang.blog.51cto.com/7876557/1669829 现在生产环境MySQL数据库是一主一从,由于业务量访 ...
- [知识库分享系列] 三、Web(高性能Web站点建设)
知识库分享系列: [知识库分享系列] 二..NET(ASP.NET) [知识库分享系列] 一.开篇 分享介绍此知识库之所以为 Web 系列,因为和 .NET 没有完全的关系,其中的技术和实践实用于各种 ...
- DB2中OLAP函数使用示例
下面的需求是将不仅获取查询的结果集,还要将结果集的SIZE返回.结果集的SIZE是无法通过CURSOR获取的. 通常聚合函数在二种情况下,使用默认分组即没有分组.可以直接使用,比如 selec ...
- Navicat for MySQL Mac 破解版
今天在macOS 系统下搭建 Java开发环境,需要配置MySQL,按照Windows的习惯,使用Navicat for MySQL 操作比较习惯.然后找不到比较好的破解版,这里介绍一个老版的,还是英 ...
- WindowsCE project missing - 转
00x0 前言 之前在Windows 7系统中开发的WindowsCE项目,最近换成Windows 10系统,需要将项目进行修改,打开项目后提示如下错误: 无法读取项目文件“App.csproj”.. ...
- Android working with Volley
Volley是google官方推出的一个开源网络访问库,在项目中直接使用它,而不需要写一大堆的重复的代码; 项目主页: https://android.googlesource.com/platfor ...
- DataContractSerializer序列化与反序列化遇到的奇怪问题
private static void Serialize1(string filename, object obj) { var stream = new F ...
- Careercup 论坛上较有意思的题目整理
# 数据结构类 ### 线段树 segment tree http://www.careercup.com/question?id=5165570324430848 找区间内的value的个数 二维线 ...
- 转:Transform Web.Config when Deploying a Web Application Project
Introduction One of the really cool features that are integrated with Visual Studio 2010 is Web.Conf ...
- JS 传递对象问题,指针引用
$(function () { var test1 = function (args) { args.name = "lcc2"; args = { name: "lcc ...