【发布时间】:2011-11-21 10:24:38
【问题描述】:
我有一个提供两个接口的 Web 服务。一个是“MyAppNameData”,另一个是“MyAppNameSync”。我正在向 WPF 应用程序添加两个服务引用。在代码中,当我使用“MyAppNameData”引用时,我没有收到错误消息。当我使用“MyAppNameSync”时,会生成以下错误:
Could not find default endpoint element that references contract 'MyAppNameSync.IMyAppNameSync' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
我以完全相同的方式添加了这两个引用,但是 MyAppNameData 是使用 BasicHttpBinding 添加的,而 MyAppNameSync 是使用 WSHttpBinding 添加的。我不知道为什么会这样。
这是来自客户端 app.config 文件的 serviceModel 元素。如您所见,有一个端点元素引用了合同“MyAppNameSync.IMyAppNameSync”,这与错误消息所说的相反:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMyAppNameData"
closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00"
sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8"
transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="WSHttpBinding_IMyAppNameSync" 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="Message">
<transport clientCredentialType="Windows"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows"
negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://computername.domainname.home/MyAppNameSyncService/MyAppNameData.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IMyAppNameData"
contract="MyAppNameData.IMyAppNameData"
name="BasicHttpBinding_IMyAppNameData" />
<endpoint address="http://computername.domainname.home/MyAppNameSyncService/MyAppNameSync.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyAppNameSync"
contract="MyAppNameSync.IMyAppNameSync"
name="WSHttpBinding_IMyAppNameSync">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
任何建议都将不胜感激。
谢谢
【问题讨论】:
-
以相同的方式添加两个引用是什么意思?您应该只需要添加一个引用,它应该创建两个代理。
-
感谢您的回复。我发布的 Web 服务中有两个 .svc 文件。 MyAppNameData.svc 和 MyAppNameSync.svc。要添加服务引用,我右键单击 Service References 节点,选择添加(其中一个 svc 文件),为其命名空间名称,然后单击确定。我对另一个 svc 文件再次执行相同操作。
-
好的,很抱歉,我以为您有一个带有两个端点的服务,但您有两个不相关的服务。
-
它是否仅适用于单个
wsHttpBinding?如果您将wsHttpBinding切换为basicHttpBinding,它是否有效?基本上,您能确定是wsHttpBinding语法导致了问题,还是有多个绑定导致了问题? -
您似乎没有尝试过 Rachel 的完整建议。你可以只引用
MyAppNameSync。在那之前,您不会知道问题是出在绑定上还是出在双重绑定上。
标签: .net wpf wcf-binding wcf-data-services