- 浏览: 246597 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (293)
- web (1)
- [随笔分类]项目管理 (30)
- [随笔分类]WCF (14)
- 未分类 (1)
- [随笔分类]Linq (4)
- [随笔分类]C#基础 (24)
- 项目 (1)
- [网站分类]3.非技术区(技术之外的文章,但不要涉及任何政治内容) (8)
- [网站分类]1.首页原创精华.NET区(包含架构设计、设计模式)(对首页文章的要求:原创、高质量、经过认真思考并精心写作) (9)
- [随笔分类]Ubuntu (4)
- ASP.Net (1)
- [网站分类]2..NET新手区(用于发表不合适发表在首页的.NET技术文章,包括小经验、小技巧) (30)
- [随笔分类]ASP.NET MVC (20)
- [随笔分类]ASP.NET (3)
- [随笔分类]程序员厨房 (4)
- [随笔分类]英语学习 (28)
- [网站分类]4.其他技术区 (1)
- [随笔分类]Silverlight (12)
- [随笔分类]CodeSmith (8)
- [随笔分类]其他 (4)
- [随笔分类]Ruby (4)
- [发布至博客园首页] (34)
- [网站分类]其他技术区 (3)
- [随笔分类]Ruby on Rails (2)
- [网站分类].NET新手区 (33)
- [随笔分类]TDD (1)
- [随笔分类]不谈技术 (2)
- [网站分类]非技术区 (7)
最新评论
-
yicone:
You make a mistake when paste t ...
WCF步步为营(一):简单示例 -
jinweijie:
你好,这个实现不错,但是在用了scriptmanager以后就 ...
在服务器端保存ViewState
1. WCF只能传输序列化的类型,WCF 能自动序列化.net内置的之类型,但是如果需要传输自定义的类型,必须把自定义的类型标注DataContract
DataContract标注这个类作为数据契约,DataMember属性指明那些字段公布为原数据,是否必需,顺序是多少。
2. 上面的定义,使得Student可以用在服务契约里,下面的Name可以让客户端的名称和服务端不同。
3. 下面是我们生成的代理类,可以看到客户端的名字,而且由于Student的Address未声明DataMember,所以客户端是不可见的
<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> -->//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.1433
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace JackWangServiceClient.CalcService {
using System.Runtime.Serialization;
using System;
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="Student", Namespace="http://schemas.datacontract.org/2004/07/JackWangWCFService")]
[System.SerializableAttribute()]
public partial class Student : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
private string FirstNameField;
private string LastNameField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private int AgeField;
[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public string FirstName {
get {
return this.FirstNameField;
}
set {
if ((object.ReferenceEquals(this.FirstNameField, value) != true)) {
this.FirstNameField = value;
this.RaisePropertyChanged("FirstName");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public string LastName {
get {
return this.LastNameField;
}
set {
if ((object.ReferenceEquals(this.LastNameField, value) != true)) {
this.LastNameField = value;
this.RaisePropertyChanged("LastName");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute(Order=2)]
public int Age {
get {
return this.AgeField;
}
set {
if ((this.AgeField.Equals(value) != true)) {
this.AgeField = value;
this.RaisePropertyChanged("Age");
}
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="CalcService.CalcService")]
public interface CalcService {
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/CalcService/AddInt", ReplyAction="http://tempuri.org/CalcService/AddIntResponse")]
long AddInt(int firstInt, int SecondInt);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/CalcService/addAgeOfStudent", ReplyAction="http://tempuri.org/CalcService/addAgeOfStudentResponse")]
JackWangServiceClient.CalcService.Student addAgeOfStudent(JackWangServiceClient.CalcService.Student student);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public interface CalcServiceChannel : JackWangServiceClient.CalcService.CalcService, System.ServiceModel.IClientChannel {
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public partial class CalcServiceClient : System.ServiceModel.ClientBase<JackWangServiceClient.CalcService.CalcService>, JackWangServiceClient.CalcService.CalcService {
public CalcServiceClient() {
}
public CalcServiceClient(string endpointConfigurationName) :
base(endpointConfigurationName) {
}
public CalcServiceClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public CalcServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public CalcServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress) {
}
public long AddInt(int firstInt, int SecondInt) {
return base.Channel.AddInt(firstInt, SecondInt);
}
public JackWangServiceClient.CalcService.Student addAgeOfStudent(JackWangServiceClient.CalcService.Student student) {
return base.Channel.addAgeOfStudent(student);
}
}
}
4. 客户端调用示例:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using JackWangServiceClient.CalcService;
namespace JackWangServiceClient
{
class Program
{
static void Main(string[] args)
{
CalcServiceClient proxy = new CalcServiceClient();
long result = proxy.AddInt(50, 60);
Student myStudent = new Student();
myStudent.FirstName = "Jack";
myStudent.LastName = "Wang";
myStudent.Age = 18;
Student resultStudent = proxy.addAgeOfStudent(myStudent);
Console.Out.WriteLine("result from server is:" + result);
Console.Out.WriteLine(resultStudent.FirstName + "," + resultStudent.LastName + "," + resultStudent.Age);
Console.ReadLine();
}
}
}
发表评论
-
WCF步步为营(一):简单示例
2008-07-02 17:13 1003本示例通过一个简单的加法服务,来演示WCF最基本的调用。 1. ... -
WCF步步为营(二):使用配置文件改变发布服务的方式
2008-07-02 17:57 6621. 打开上一个项目 2. 修改Program.cs, 注 ... -
WCF步步为营(三):使用配置文件改变使用服务的方式
2008-07-03 10:57 7091. 打开上节的解决方案 ... -
WCF步步为营(四):客户端使用代理类使用服务
2008-07-03 13:13 952首先,客户端要使用服务端的服务,首先必须知道服务的契约。服务端 ... -
WCF跟踪调试
2009-03-16 11:56 1920WCF提供了两个工具可以跟踪WCF的调用过程,我主要是用来跟踪 ... -
使用Fiddler测试WCF
2009-04-27 14:47 1552之前自己为测试人员写了个工具来测试WCF,但是当时是硬编码的, ... -
WCF 小提示:Contract-First时的注意事项
2009-04-30 12:05 736在Contract-First的模式下 我们使用svcuti ... -
[Tips]:SQL server 2005 Create Assembly Failed
2009-05-14 16:45 1092今天创建SQL server2005 程序集时,提示权限失败, ... -
WCF步步为营(一):简单示例
2008-07-02 17:13 1271本示例通过一个简单的加法服务,来演示WCF最基本的调用。 1. ... -
WCF步步为营(二):使用配置文件改变发布服务的方式
2008-07-02 17:57 8681. 打开上一个项目 2. 修改Program.cs, 注 ... -
WCF步步为营(三):使用配置文件改变使用服务的方式
2008-07-03 10:57 8741. 打开上节的解决方案,为JackWangServiceCl ... -
WCF步步为营(四):客户端使用代理类使用服务
2008-07-03 13:13 1510首先,客户端要使用服务端的服务,首先必须知道服务的契约。服务端 ... -
WCF步步为营(五):数据契约
2008-07-03 17:11 8741. WCF只能传输序列化的类型,WCF 能自动序列化.net ...
相关推荐
讲解WCF技术的,适合各种阶段的学习。从入门到进阶。
构建WCF面向服务的应用程序系列课程:WCF契约设计
WCF之旅:一个简单的WCF程序(vs2010源码) 文章 + 源码 入门首选文章,折腾了好久才折腾出第一个wcf程序。 对准备学习wcf的人员绝对有意义
WCF全面解析:上册.part3.rar
(2):WCF契约设计-WCF课件-《构建WCF面向服务的应用程序》
WCF全面解析:上册.part2.rar
构建WCF面向服务的应用程序系列课程(2):WCF契约设计
构建WCF面向服务的应用程序系列课程(2):WCF契约设计.zip
我的WCF之旅- 创建一个简单的WCF程序 - Artech WCF入门之选绝佳的例子 代源源于:《WCF全面解析 上》 编程工具:VS2010 语言:C# blog 《IIS站点中部署 WCF项目》
《WCF全面解析(套装上下册)》由蒋金楠所著,是作者多年潜心研究WCF技术的心血之作,也是这些年来从事WCF开发的经验总结。 因为上传大小限制,分卷压缩了三个rar,请全部下载完成后解压缩。
在本次的课程中,我们将向大家介绍设计服务契约,数据契约和消息契约的实用 指导,向大家展示什么时候,以及如何使用它们。同时,在本次课程中您将学习到如何处理复杂类型的序列化,如何使用契约,以及在哪里处理...
(3):契约版本处理-WCF课件-《构建WCF面向服务的应用程序》
演示了WCF怎样进行序列化复杂类型,使用DATACONTRACT进行数据序列化。
WCF数据契约实例源码;从最简单的步骤开始,一步一步学会契约的使用
1:创建第一个WCF服务 2:使用IIS发布WCF服务 3:自运行WCF服务 4:使用Windows服务发布WCF服务 5:创建WCF客户端程序
对wcf中[DataContract]的描述
“双工”示例演示如何定义和实现双工协定。 当客户端与服务建立会话并为服务提供可用来将消息发送回客户端的通道时,就会发生双工通信。
对于初学者 会有帮助 ...数据契约(Data Contract):定义于服务交互的数据类型。 3.错误契约(Fault Contract):定义抛出的错误。 4.消息契约(Message Contract):定义直接与服务交互的消息。
1:创建第一个WCF服务 2: 使用IIS发布WCF服务 3:自运行WCF服务 4:使用Windows服务发布WCF服务 5:创建WCF客户端程序
WCF 元数据浏览器 WCF 元数据浏览器