1.代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text; namespace WcfServiceLibrary1
{
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IService1”。
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value); [OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite); // TODO: 在此添加您的服务操作
}
// 使用下面示例中说明的数据约定将复合类型添加到服务操作。
// 可以将 XSD 文件添加到项目中。在生成项目后,可以通过命名空间“WcfServiceLibrary1.ContractType”直接使用其中定义的数据类型。
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello "; [DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}

  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text; namespace WcfServiceLibrary1
{
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的类名“Service1”。
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
} public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
}

  APP.config 代码

<?xml version="1.0" encoding="utf-8" ?>
<configuration> <system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8733/WcfServiceLibrary1/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- 除非完全限定,否则地址将与上面提供的基址相关 -->
<endpoint address="" binding="basicHttpBinding" contract="WcfServiceLibrary1.IService1">
<!--
部署时,应删除或替换下列标识元素,以反映
用来运行所部署服务的标识。删除之后,WCF 将
自动推断相应标识。
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- 元数据交换终结点供相应的服务用于向客户端做自我介绍。 -->
<!-- 此终结点不使用安全绑定,应在部署前确保其安全或将其删除-->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 为避免泄漏元数据信息,
请在部署前将以下值设置为 false -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<!-- 要接收故障异常详细信息以进行调试,
请将以下值设置为 true。在部署前设置为 false
以避免泄漏异常信息-->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

2添加引用

Service References-〉 右键添加服务引用-〉输入http://localhost:8733/WcfServiceLibrary1/Service1/ -〉点击发现-〉电击添加

调用

ServiceReference1.Service1Client s = new ServiceReference1.Service1Client();
Response .Write (s.GetData(5857585));
s.Close();

最新文章

  1. 【分布式】Zookeeper使用--Java API
  2. IOS开发基础知识碎片-导航
  3. SQL Server 修改表结构后无法保存的老问题
  4. 【BFS】POJ 3278
  5. A multi-faceted language for the Java platform
  6. 怎样在VS2010中打开VS2012的项目
  7. WordPress主题制作函数
  8. 81 Search in Rotated Sorted Array II
  9. VS 与 SQLite数据库 连接
  10. 射手网字幕打包下载(73.16G)
  11. hdu 3804 树链剖分
  12. UIView 中 frame, bounds, center 属性的关系
  13. appium 真机测试问题 出现 instruments crashed on startup
  14. Thrift实现C#通讯服务程序
  15. 在使用cognos时遇到的问题记录帖
  16. 路由-when-resolve
  17. 201521123002《Java程序设计》第9周学习总结
  18. 基于redis的延迟消息队列设计(转)
  19. top命令查看进程下线程信息以及jstack的使用
  20. 关于shader的学习

热门文章

  1. JDK源码阅读--ArrayList
  2. spring boot 监听容器启动
  3. windows server 文件夹和搜索选项被禁用了
  4. HBase访问接口
  5. 在mac下怎么配置web环境(php)
  6. hdu4764
  7. mysql导入数据
  8. cannot be cast to javax.servlet.Servlet 解决
  9. 19-10-23-L-Mor
  10. 什么情况下要加上【javascript:】