2012-07-12 61 views
1

我有非常具体的问题。 如果我创建一个WCF服务,并且它有多个端点名称,如何使用浏览器访问该端点? 另外我怎样才能通过添加服务参考访问我的客户端应用程序?如何在服务参考中使用WCF服务如果它有多个端点名称

像我的配置代码:

<services> 
    <service name="MultipleEndpoint.SampleService" behaviorConfiguration="MultipleEndpoint.SampleService"> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost:55052/SampleService.svc"/> 
     </baseAddresses> 
    </host> 
    <endpoint address="/basic" binding="basicHttpBinding" contract="MultipleEndpoint.ISampleService" bindingConfiguration="basicBinding" > 
    </endpoint> 
    <endpoint address="/wsHttp" binding="wsHttpBinding" contract="MultipleEndpoint.ISampleService" bindingConfiguration="wsBinding" >   
    </endpoint> 
    <endpoint address="/webHttp" binding="webHttpBinding" contract="MultipleEndpoint.ISampleService" behaviorConfiguration="REST"> 
    </endpoint>   
    </service> 
</services> 

现在,当我试图访问使用

http://localhost:55052/SampleService.svc/basic or 
http://localhost:55052/SampleService.svc/wsHttp 

它给了我没有找到IE标准错误信息页/资源... 同时我想知道如何将这种类型的url作为服务引用添加到我的客户端应用程序中?

回答

0

这些服务的地址是不同的,它们不是严格必须眉紫貂,意味着你不能浏览服务端点像的http://本地主机:55052/SampleService.svc /基本这些地址用于区分通信中的端点

如果您看到服务的wsdl,那么在那里指定那些端点的所有地址。

如果您创建服务,通过“添加服务引用”的所有端点在配置中创建单独像代理..

<client> 
    <endpoint address="http://localhost:54671/Service1.svc/basic" 
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" 
      contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" /> 

    <endpoint address="http://localhost:54671/Service1.svc/ws" binding="wsHttpBinding" 
      bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1" 
      name="WSHttpBinding_IService1"> 
    </endpoint> 
    ... 
</client> 

说,如果你想使用基本的HTTP交谈的服务端点,那么您可以通过在ctor中传递相应的端点配置name来为其创建代理。

Ex。

// this will uses the basic http endpoint. 
Service1Client client = new Service1Client("BasicHttpBinding_IService1");