【发布时间】:2013-02-22 13:28:50
【问题描述】:
我在尝试从 c# 客户端访问托管在 iis(本地)中的 WCF 服务时收到此错误:
找不到名称为“X”和合同“合同”的端点元素 ServiceModel 客户端配置部分中的名称。这可能是 因为没有为您的应用程序找到配置文件,或者 因为在 客户端元素。
这是客户端的 app.config(它是一个 NUnit 夹具,只是为了测试连接):
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_MyWs" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost/MyWs/MyWs.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MyWs"
contract="MyServiceSvc.IMyWs"
name="BasicHttpBinding_MyWs" />
</client>
</system.serviceModel>
</configuration>
如果我浏览
https://localhost/MyWs/MyWs.svc?wsdl
我得到了正确的输出,所以服务器部分工作正常。
此外,我可以使用soapUI 测试我的ws,所以问题一定出在客户端,可能在app.config 中。
我的客户端代码,以防有人想看:
[TestFixture]
public class MyWsProxyFixture
{
private readonly MyWsClient _client = new MyWsClient();
[Test]
public void ProxyCreation()
{
Assert.IsNotNull(_client);
}
//More tests here
}
更有趣的是,完全相同的配置和客户端可以在另一台机器上运行。是的,它是真的。我自己都不敢相信,但事实就是如此。
您能否提供一些提示或建议来解决这个问题?
谢谢!
PS:客户端中的服务引用没问题。
【问题讨论】:
-
请提供您的解决方案结构,以便我可以相应地更新我的答案。
-
我的解决方案:1个使用其他各种组件(类库项目)的wcf服务和客户端的类库项目
-
您可以发布您的客户端代码吗?另外,您是在使用 WCF 服务的添加服务引用,还是从 WSDL 生成代理并将其包含在客户端项目中?同样在客户端配置中,我可以看到合同值有一个命名空间,并希望接口也在客户端项目中的同一命名空间中
-
查看我的编辑。是的,服务器和客户端中的命名空间是相同的。另外,如果我改变它似乎并不重要......它总是给我同样的例外......
标签: c# wcf web-services