Getting Exception while working with multiple endpoints
I was trying to create a WCF application with multiple endpoints, but while accessing it using a client(console application) , I am getting below excption:
Could not find endpoint element with name 'SS2' and contract 'IStockService' 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 name could be found in the client element.
What I did: Service Side:
Code:
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();
}
}
config:
<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>
}
Now using svcutil.exe I created one config and proxy class, then added one App.config to my client console and copy paste the contents in that file (from svcutil) and tried to access the service.
Client Code:
StockServiceClient proxy = new StockServiceClient("SS2");
Console.WriteLine(proxy.GetDataForSS2(15));
Console.ReadKey();
config:
<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" maxReceivedMe开发者_Go百科ssageSize="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>
I think the way I am declaring <baseaddress>
is wrong,(in service config file)
<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>
Any clue where I am going wrong
EDIT: Not sure why Nix Deleted his ans, I implemented his suggestions and it was working.
So besides directing you in the wrong direction (sorry) you are using the wrong Client! There should be another client in your endpoint called(or close to).
StockServiceSS2Client client = new StockServiceSS2Client();
And it will work like a champ.
What was happening was you were specifying and endpoint with a different contract then what the client class was looking for.
Sorry for the confusion.
精彩评论