我試圖創建多個端點WCF應用程序,但在使用客戶端(控制檯應用程序)訪問它,我得到以下excption工作時:獲取異常與多個端點
找不到終點元素在ServiceModel客戶端配置部分中名稱爲'SS2'並簽約'IStockService'。這可能是因爲沒有爲您的應用程序找到配置文件,或者因爲在客戶端元素中找不到匹配此名稱的端點元素。
我所做的: 服務端:
代碼:
public interface IStockService1 {
[OperationContract]
string GetDataForSS1(int value);
}
[ServiceContract]
public interface IStockService2 {
[OperationContract]
string GetDataForSS2(int value);
}
[ServiceContract]
public interface IStockService:IStockService1,IStockService2 {
[OperationContract]
string GetDataForSS3(int value);
}
public class StockService : IStockService{
public string GetDataForSS3(int value){
return "SS3"+value.ToString();
}
public string GetDataForSS1(int value){
return "SS1"+value.ToString();
}
public string GetDataForSS2(int value){
return "SS2"+ value.ToString();
}
}
配置:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="MultipleEndpointsDemo.StockService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:1832/StockService.svc/"/>
</baseAddresses>
</host>
<endpoint name="StockServiceSS1" address="SS1" binding="basicHttpBinding" contract="MultipleEndpointsDemo.IStockService1"/>
<endpoint name="StockServiceSS2" address="SS2" binding="basicHttpBinding" contract="MultipleEndpointsDemo.IStockService2"/>
<endpoint name="StockService" address="all" binding="basicHttpBinding" contract="MultipleEndpointsDemo.IStockService"/>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
}
現在使用svcutil.exe的我創建一個配置和代理類,然後加入一個App.config到我的客戶端控制檯並複製粘貼該文件中的內容(來自svcutil)並嘗試訪問該服務。
客戶端代碼:
StockServiceClient proxy = new StockServiceClient("SS2");
Console.WriteLine(proxy.GetDataForSS2(15));
Console.ReadKey();
配置:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="StockServiceSS1" 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>
<binding name="StockServiceSS2" 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>
<binding name="StockService" 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>
</bindings>
<client>
<endpoint address="http://localhost:1832/StockService.svc/SS1"
binding="basicHttpBinding" bindingConfiguration="StockServiceSS1"
contract="IStockService1" name="StockServiceSS1" />
<endpoint address="http://localhost:1832/StockService.svc/SS2"
binding="basicHttpBinding" bindingConfiguration="StockServiceSS2"
contract="IStockService2" name="StockServiceSS2" />
<endpoint address="http://localhost:1832/StockService.svc/all"
binding="basicHttpBinding" bindingConfiguration="StockService"
contract="IStockService" name="StockService" />
</client>
</system.serviceModel>
</configuration>
我想我聲明<baseaddress>
的方式是錯誤的,(在服務配置文件)
<service name="MultipleEndpointsDemo.StockService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:1832/StockService.svc/"/>
</baseAddresses>
</host>
<endpoint name="StockServiceSS1" address="SS1" binding="basicHttpBinding" contract="MultipleEndpointsDemo.IStockService1"/>
<endpoint name="StockServiceSS2" address="SS2" binding="basicHttpBinding" contract="MultipleEndpointsDemo.IStockService2"/>
<endpoint name="StockService" address="all" binding="basicHttpBinding" contract="MultipleEndpointsDemo.IStockService"/>
</service>
任何線索,其中我出錯了
編輯:不知道爲什麼尼克斯刪除了他的答案,我實現了他的建議,它工作。
實際上http:// localhost:1832/StockService.svc/SS1和http:// localhost:1832/StockService.svc/SS2不是有效地址,我在找到頁面時找不到錯誤,而點擊了url – Wondering 2010-09-30 14:00:33
only localhost :1832/StockService.svc工作正常 – Wondering 2010-09-30 14:02:06