我有一個提供兩個接口的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
好的,我很抱歉,我以爲你有兩個端點的單一服務,但你有兩個無關的服務。 –