2010-09-30 33 views
0

我试图创建多个端点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> 

任何线索,其中我出错了

编辑:不知道为什么尼克斯删除了他的答案,我实现了他的建议,它工作。

+0

实际上http:// localhost:1832/StockService.svc/SS1和http:// localhost:1832/StockService.svc/SS2不是有效地址,我在找到页面时找不到错误,而点击了url – Wondering 2010-09-30 14:00:33

+0

only localhost :1832/StockService.svc工作正常 – Wondering 2010-09-30 14:02:06

回答

1

所以,除了指导你在错误的方向(对不起),你正在使用错误的客户端!您的端点中应该有另一个客户端调用(或接近)。

StockServiceSS2Client client = new StockServiceSS2Client(); 

它会像冠军一样工作。

发生了什么事情是您指定的,并且终端具有不同的契约,然后客户端类正在寻找什么。

对不起,我感到困惑。

+0

哦,好吧..从我这边来看,这是一个糟糕的错误。感谢您的所有帮助和时间。 – Wondering 2010-09-30 15:17:49