积极答复者
关于WCF

问题
-
做了个WCF。想在启动服务的时候初始化一些静态数据。
用了一个笨办法:一个程序同时作为宿主程序和客户端程序,在打开WCF服务后再去调用WCF程序,用这样的办法初始化全部静态数据。
但是没有成功,无法通讯,直至TimeOut。但新建一个项目作为客户端访问没有问题。请求帮助
App.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<!-- 部署服务库项目时,必须将配置文件的内容添加到
主机的 app.config 文件中。System.Configuration 不支持库的配置文件。-->
<system.serviceModel>
<client>
<endpoint address="http://192.168.9.125:8085" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService1" contract="Server.IService1"
name="WSHttpBinding_IService1" />
</client>
<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="None">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true" />
</security>
</binding>
</wsHttpBinding>
<!--<wsHttpBinding>
<binding name="FBI_BINDING" maxBufferPoolSize="12000000" maxReceivedMessageSize="12000000" useDefaultWebProxy="true">
<readerQuotas maxStringContentLength="12000000" maxArrayLength="12000000"/>
<security mode="None"/>
</binding>
</wsHttpBinding>-->
</bindings><services>
<service name="TaoBaoServer.Service1" behaviorConfiguration="taobaoBehavior">
<host>
<baseAddresses>
<add baseAddress = "http://192.168.9.125:8085/" />
<add baseAddress = "net.tcp://192.168.9.125:8085/"/>
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- 除非完全限定,否则地址将与上面提供的基址相关 -->
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1" contract="TaoBaoServer.IService1">
</endpoint>
<!-- Metadata Endpoints -->
<!-- 元数据交换终结点由服务用于向客户端做自我描述。-->
<!-- 此终结点不使用安全绑定,应在部署前确保其安全或将其删除-->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service></services>
<behaviors>
<serviceBehaviors>
<behavior name="taobaoBehavior">
<!-- 为避免泄漏元数据信息,
请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
<serviceMetadata httpGetEnabled="false"/>
<!-- 要接收故障异常详细信息以进行调试,
请将下值设置为 true。在部署前
设置为 false 以避免泄漏异常信息-->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<!--<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>-->
</configuration>Server.cs
ServiceHost host = null;
host = new ServiceHost(typeof(TaoBaoServer.Service1));
host.Open();
System.Threading.Thread.Sleep(1000);
Server.Service1Client server = new Server.Service1Client();
server.serverInit();
答案
-
是不是线程死锁了。
你多启动一个线程来Host WCF服务,然后主线程调用WCF服务。
或者干脆 拆成2个程序,这么最简单。
Frank Xu Lei--谦卑若愚,好学若饥
【老徐的网站】:http://www.frankxulei.com/- 已标记为答案 Peter pi - MSFTModerator 2012年1月23日 0:51
全部回复
-
是不是线程死锁了。
你多启动一个线程来Host WCF服务,然后主线程调用WCF服务。
或者干脆 拆成2个程序,这么最简单。
Frank Xu Lei--谦卑若愚,好学若饥
【老徐的网站】:http://www.frankxulei.com/- 已标记为答案 Peter pi - MSFTModerator 2012年1月23日 0:51