WCF之 结案陈词

ServiceHosthost = newServiceHost(typeof(Service), http://localhost:8080/ddd);

只适用于自托管,"http://localhost:8080/ddd"是baseAddress,也可以把地址放到配置文件中:

ServiceHost host = new ServiceHost(typeof(Service));

      <service name="WcfServiceLibrary2.Service1" behaviorConfiguration="WcfServiceLibrary2.Service1Behavior">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8080/ddd/" />
          </baseAddresses>
        </host>
        <endpoint address ="" binding="wsHttpBinding" contract="WcfServiceLibrary2.IService1">

 

注意,不要这么设置:

ServiceHost host = new ServiceHost(typeof(Service), "http://localhost:8080/ddd");

      <service name="WcfServiceLibrary2.Service1" behaviorConfiguration="WcfServiceLibrary2.Service1Behavior">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary2/Service1/" />
          </baseAddresses>
        </host>
        <endpoint address ="" binding="wsHttpBinding" contract="WcfServiceLibrary2.IService1">

我测试过,运行时报错了,不能同时设置两个baseAddress,在运行ServiceHost 的ctor时,会发现baseAddress已经存在了(就是配置文件中的那个)。

 

在IIS中,不需要baseAddress,我试着加了一下,发现即使加了Host和baseAddress,也不会生效。

 

          <identity>
            <dns value="localhost"/>
          </identity>

identity这个标签,不要也罢,它是为开发阶段而设计的,deploy时remove掉。

 

 

1.不在Client端添加Server Reference,也能得到服务么?

如果Server端的Service不具有MEX绑定,那就不能在Client端添加Server Reference了,不信你就试试。

在这种情况下,我们该如何在Client端得到Service呢?

这时候,我们就要使用svcutil命令行工具,手动生成Service的代理类:

比如说,我写了一个ClassLibrary,注意,仅仅是一个ClassLibrary,然后我添加了System.ServiceModel命名空间,定义了契约及其实现,并把它们

 

3.MEX究竟是干什么用的?

 

4.如果我把svc和cs代码分成两个project?

 

 

6.究竟是App.config还是web.config?

 

 

7.Add Service Reference只针对IIS托管么?

 

8.

posted @   包建强  Views(505)  Comments(0Edit  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
历史上的今天:
2007-10-23 我也设计模式——16.Interpreter
点击右上角即可分享
微信分享提示