积极答复者
WCF中,加了namespace后,就获取不到Endpoint了?

问题
-
刚接触WCF,有很多不清楚的地方,希望各位牛人指教。
程序基本结构如下:
通过IIS配置service : http://localhost:8001/CalculatorService.svc
console程序作为client: 通过 “svcutil /language:cs /out:clientProxy.cs /config:app.config http://localhost:8001/CalculatorService.svc” 生成client类,以及app.config,并将这两个文件加入工程中。
1)app.config 如下:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ICalculator" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8001/CalculatorService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICalculator"
contract="ICalculator" name="WSHttpBinding_ICalculator">
<identity>
<servicePrincipalName value="host/SP-WorkStation" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>2)clientProxy.cs 中保留自动生成的样式,这里简化自动生成代码为 A。
3)console的Program.cs,如下
static void Main(string[] args)
{
CalculatorClient client = new CalculatorClient("WSHttpBinding_ICalculator");// Call the Add service operation.
double value1 = 100.00D;
double value2 = 15.99D;
double result = client.Add(value1, value2);
Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
}这个时候,运行没有任何问题。
但是,
1)在clientProxy.cs加入namespace后,如下 :
namespace SP.CalculatorServiceForIISUsingSvcutil
{A
}2)在app.config中,修改
<endpoint address="http://localhost:8001/CalculatorService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICalculator"
contract="SP.CalculatorServiceForIISUsingSvcutil.ICalculator" name="WSHttpBinding_ICalculator">再运行,就会在“CalculatorClient client = new CalculatorClient("WSHttpBinding_ICalculator");”报如下错误
“在 ServiceModel 客户端配置部分中,找不到名称“WSHttpBinding_ICalculator”和协定“ICalculator”的终结点元素。这可能是因为未找到应用程序的配置文件,或者是因为客户端元素中找不到与此名称匹配的终结点元素。”
不清楚是什么原因,请各位不吝赐教。
现在正学习WCF,如果有对WCF感兴趣的朋友,加QQ 75167211,彼此可以讨论一下。
多谢:)
答案
-
ICalculator 这个契约接口 你加了嘛???不要只加类型
Frank Xu Lei--谦卑若愚,好学若饥
[老徐的网站]:http://www.frankxulei.com/[老徐的博客]:http://54peixun.com/Author/frankxulei
微软WCF中文技术论坛
微软WCF英文技术论坛
Windows Azure中文技术论坛- 已标记为答案 Haixia_XieModerator 2012年11月12日 9:10
-
把 contract="SP.CalculatorServiceForIISUsingSvcutil.ICalculator"保留原有,即 contract="ICalculator",就没问题了。。。
有点糊涂,在Service Hosting时,app.config中contract必须要带namespace,为什么client就不需要了?
快乐在于能够长时间的为自己认为值得的事情努力工作,不管它是什么。
- 已标记为答案 Haixia_XieModerator 2012年11月12日 9:10
全部回复
-
ICalculator 这个契约接口 你加了嘛???不要只加类型
Frank Xu Lei--谦卑若愚,好学若饥
[老徐的网站]:http://www.frankxulei.com/[老徐的博客]:http://54peixun.com/Author/frankxulei
微软WCF中文技术论坛
微软WCF英文技术论坛
Windows Azure中文技术论坛- 已标记为答案 Haixia_XieModerator 2012年11月12日 9:10
-
把 contract="SP.CalculatorServiceForIISUsingSvcutil.ICalculator"保留原有,即 contract="ICalculator",就没问题了。。。
有点糊涂,在Service Hosting时,app.config中contract必须要带namespace,为什么client就不需要了?
快乐在于能够长时间的为自己认为值得的事情努力工作,不管它是什么。
- 已标记为答案 Haixia_XieModerator 2012年11月12日 9:10