一天学习成果,wcf项目,欢迎大家鄙视、

弦弦 2011-08-23 05:46:42
IService和Service中的代码就不写了。一个简单的Add(int a,int b)的方法

这个是在winform中的代码
ServiceHost host = null;
ServiceReference1.Service1Client cli = new WindowsForm.ServiceReference1.Service1Client();
private void button1_Click(object sender, EventArgs e)
{

host = new ServiceHost(typeof(WcfServiceLibrary.Service1));
lblsum.Text ="两数之和是:"+ cli.Add(Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox2.Text)).ToString();
}




客户端app.config

<?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>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary/Service1/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
contract="ServiceReference1.IService1" name="WSHttpBinding_IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<services>
<!--添加服务-->
<service name="WcfServiceLibrary.Service1" behaviorConfiguration="CalculatorServiceBehavior">
<!--name 必须与代码中的host实例初始化的服务一样
behaviorConfiguration 行为配置 -->
<host>
<baseAddresses>
<!--添加调用服务地址-->
<add baseAddress="http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary/Service1/"/>
</baseAddresses>

</host>
<!--添加契约接口 contract="WcfDemo.IService1" WcfDemo.IService1为契约接口 binding="wsHttpBinding" wsHttpBinding为通过Http调用-->
<endpoint address="" binding="wsHttpBinding" contract="WcfServiceLibrary.IService1"></endpoint>
</service>

</services>
<!--定义CalculatorServiceBehavior的行为-->
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>

</behavior>

</serviceBehaviors>

</behaviors>
</system.serviceModel>
</configuration>


不过我有一个疑问:在Web项目中用这个WCF。大概就0.0X秒的样子。数据就出现了
在Winform中,需要大概[color=#FF00005[/color]秒时间。为什么啊?
...全文
118 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
子夜__ 2011-08-23
  • 打赏
  • 举报
回复
鄙视完毕 哈哈
CalvinR 2011-08-23
  • 打赏
  • 举报
回复
楼主好样的 顶帖啊………………
摩羯伙夫 2011-08-23
  • 打赏
  • 举报
回复
顶一下
弦弦 2011-08-23
  • 打赏
  • 举报
回复
在Winform中,需要大概6秒时间。为什么啊?

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧