您的位置:首页 > 其它

WCF服务的创建和发布到IIS

2016-05-06 19:04 627 查看
一、 WCF服务的创建

有两种创建方式:

1.WCF服务库

2.WCF服务应用程序

如下图所示:



<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
<binding name="WSHttpBinding_IService11" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://127.0.0.1:7293/WCFServerUseWCFLib.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
contract="WCFServerUseWCFLib.IService1" name="WCFServerUseWCFLibIService">
<identity>
<servicePrincipalName value="host/weiMe-PC" />
</identity>
</endpoint>
<endpoint address="http://127.0.0.1:7294/WCFServerRefWCFLib.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService11"
contract="WCFServerRefWCFLib.IService1" name="WCFServerRefWCFLibIService">
<identity>
<servicePrincipalName value="host/weiMe-PC" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>


步骤3:

导入命名空间:

using WpfApplication1.WCFServerUseWCFLib;

调用WCF服务(这里调用方法 :

string GetData(int)

private void BtnWCFLibToIIS_OnClick(object sender, RoutedEventArgs e)
{
using (WCFServerUseWCFLib.Service1Client proxy = new WCFServerUseWCFLib.Service1Client())
{
MessageBox.Show(this.BtnWCFWebRefWCFLibTOIIS.Content.ToString() + proxy.GetData(2));
}
}


如果要客户端要使用异步编程,可以让客户端代理支持异步编程,做法是:

1.右键WCF服务的引用---选择“配置服务引用”。



2.在弹出的对话框中,勾选“生成异步操作”--点击“确定”按钮。



[b]四、解决方案




【The End】
http://www.cnblogs.com/easy5weikai/p/3341147.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: