ASP.net中使用WCF小结:
1.建立contact:
[ServiceContract]
public interface IStudent
{
[OperationContract]
string GetName(string firstName, string lastName);
}
实现:
public class Student:IStudent
{
public string GetName(string firstName, string lastName)
{
return lastName+firstName;
}
}
2.建立服务端(web):
添加一个service.svc,去掉其C#文件,代码:
<%@ServiceHost language=c# Debug="true" Service="Contact.Student" %>
让其指向实现了contact的类
Web.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service
name="Contact.Student"
behaviorConfiguration="Contact_Student">
<endpoint address="" binding="wsHttpBinding" contract="Contact.IStudent" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Contact_Student">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
将其发布到IIS中去
3.建立客户端(web):
有IIS中浏览service.svc,将其地址:http://localhost:90/WCFTest/service.svc复制
用SvcUtil生成代理与output.config(SvcUtil http://localhost:90/WCFTest/service.svc回车即可)
将output.config内容考到Web.config中去即可。
建立一个default.aspx页:
测试如下:
protected void Page_Load(object sender, EventArgs e)
{
StudentClient proxy = new StudentClient();
string name = proxy.GetName("xiancheng", "ou");
Response.Write(name);
}
没有合适的资源?快使用搜索试试~ 我知道了~
WCF+Asp.net
共52个文件
cs:13个
pdb:9个
dll:9个
4星 · 超过85%的资源 需积分: 6 70 下载量 177 浏览量
2009-04-28
09:40:25
上传
评论 1
收藏 58KB RAR 举报
温馨提示
WCF+Asp.net WCF+Asp.net WCF+Asp.net WCF+Asp.net WCF+Asp.net
资源推荐
资源详情
资源评论
收起资源包目录
WCF+Asp.net.rar (52个子文件)
WCF+Asp.net
WcfServerTest.suo 38KB
Server
Server.Publish.xml 1KB
Server.csproj 5KB
bin
Server.pdb 12KB
Contact.dll 4KB
Server.dll 4KB
Contact.pdb 12KB
service.svc 72B
Web.config 641B
obj
Debug
Server.pdb 12KB
Server.dll 4KB
ResolveAssemblyReference.cache 7KB
Server.csproj.FileListAbsolute.txt 1KB
Refactor
TempPE
Server.csproj.user 1KB
Properties
AssemblyInfo.cs 1KB
App_Data
Default.aspx 473B
Default.aspx.cs 501B
Default.aspx.designer.cs 811B
Contact
bin
Debug
Contact.dll 4KB
Contact.pdb 12KB
obj
Debug
Contact.dll 4KB
Contact.csproj.FileListAbsolute.txt 1KB
Refactor
TempPE
Contact.pdb 12KB
Properties
AssemblyInfo.cs 1KB
IStudent.cs 303B
Student.cs 297B
Contact.csproj 3KB
WCF+Asp.net.txt 2KB
WcfServerTest
bin
Debug
WcfServerTest.dll 5KB
WcfServerTest.pdb 16KB
obj
Debug
WcfServerTest.dll 5KB
WcfServerTest.pdb 16KB
Refactor
TempPE
WcfServerTest.csproj.FileListAbsolute.txt 703B
Properties
AssemblyInfo.cs 1KB
IService1.cs 1KB
WcfServerTest.csproj 3KB
Service1.cs 749B
WcfServerTest.sln 2KB
WcfClient
bin
WcfClient.dll 6KB
WcfClient.pdb 14KB
Web.config 9KB
obj
Debug
WcfClient.dll 6KB
WcfClient.pdb 14KB
Refactor
TempPE
WcfClient.csproj.FileListAbsolute.txt 475B
Properties
AssemblyInfo.cs 1KB
WcfClient.csproj 4KB
App_Data
Default.aspx 457B
Student.cs 2KB
Default.aspx.cs 654B
WcfClient.csproj.user 1KB
Default.aspx.designer.cs 802B
output.config 2KB
共 52 条
- 1
oxch2008
- 粉丝: 3
- 资源: 72
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页