我有一个提供两个接口的Web服务。一个是“MyAppNameData”,另一个是“MyAppNameSync”。我将两个服务引用添加到WPF应用程序。在代码中,当我使用“MyAppNameData”引用时,我不会收到错误。当我使用产生“MyAppNameSync”以下错误:提供两个接口的Web服务导致WPF应用程序出错
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.
我加了两个引用的方式不尽相同,但是,使用带有WsHttpBinding的加入basicHttpBinding的和MyAppNameSync加入MyAppNameData。我不知道为什么是这样。
这是客户端的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。要添加服务引用,我右键单击服务引用节点,选择添加,其中一个svc文件,为其命名空间名称,然后单击确定。我再次为其他svc文件做同样的事情。 – rogdawg
好的,我很抱歉,我以为你有两个端点的单一服务,但你有两个无关的服务。 –