以配置的方式实现WCF的服务端和客户端的配置

今天的错误非常之揪心,在配置WCF服务的时候,使用配置文件进行设置,在其中出现错误,接口或者服务找不到

解决方法:取消使用服务配置方式,使用代码注册,如果可以成功,则十有八九是因为自己的代码里面的命名空间或者是类名写错了
因为在xml编辑器里面写的时候,是自己手写而不是通过代码提示点出来的,最好使用复制。
另,附上服务端和客户端配置方式(命名均为App.Config)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="Service.CalService" behaviorConfiguration="Myservice">
        <endpoint address="net.tcp://localhost:1234/Calservice" binding="netTcpBinding" contract="Contract.IService"></endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Myservice">
          <serviceMetadata httpGetEnabled="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>
其中在服务端配置时的name不能随便写,要写成是实现契约接口的服务类
客户端配置
 1 <?xml version="1.0" encoding="utf-8" ?>
 2 <configuration>
 3   <system.serviceModel>
 4     <client>
 5       <endpoint name="Calser"
 6                 address="net.tcp://localhost:1234/Calservice"
 7                 binding="netTcpBinding"
 8                 contract="Contract.IService"></endpoint>
 9     </client>
10   </system.serviceModel>
11 </configuration>

 

posted @ 2012-12-26 19:51  oeaker  阅读(994)  评论(0编辑  收藏  举报