2009-03-02 163 views
5

我在尝试将WCF测试客户端与我的WCF服务一起使用时出现错误。下面是服务代码:WCF测试客户端错误:无法调用服务

[ServiceContract] 
public interface IEmployeeService 
{ 
    [OperationContract(Name = "GetEmployee")] 
    [WebGet(RequestFormat = WebMessageFormat.Xml, 
     UriTemplate = "/Employees/{employeeNumber}")] 
    Employee GetEmployee(string employeeNumber); 
} 

public Employee GetEmployee(string employeeNumber) 
{ 
    var employeeNumberValue = Convert.ToInt32(employeeNumber); 
    var employee = DataProvider.GetEmployee(employeeNumberValue); 
    return employee; 
} 

<system.serviceModel> 
    <services> 
     <service name="Employees.Services.EmployeeService" 
       behaviorConfiguration="metaBehavior"> 
      <endpoint address="" 
         behaviorConfiguration="webHttp" 
         binding="webHttpBinding" 
         contract="Employees.Services.IEmployeeService"> 
      </endpoint> 
      <endpoint address="mex" 
         binding="mexHttpBinding" 
         contract="IMetadataExchange"> 
      </endpoint> 
     </service> 
    </services> 
    <behaviors> 
     <endpointBehaviors> 
      <behavior name="webHttp"> 
       <webHttp/> 
      </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
      <behavior name="metaBehavior"> 
       <serviceMetadata httpGetEnabled="true" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
</system.serviceModel> 

我能够连接到使用WCF测试客户端的服务,但是当我尝试调用getEmployee的(employeeNumber)我得到以下错误:

失败调用服务。可能的原因:服务处于脱机状态或无法访问;客户端配置与代理不匹配;现有的代理无效。有关更多详细信息,请参阅堆栈跟踪。您可以尝试通过启动新代理,还原为默认配置或刷新服务来进行恢复。

我能够通过从浏览器发送请求来成功调用此服务。

任何想法,为什么我不能使用WCF测试客户端?

回答

11

请忽略我以前的答案。我认为问题不在客户端配置。

请参阅WCF Test Client and WebHttpBinding

This is a limitation of the web programming model itself. Unlike SOAP endpoints (i.e., those with BasicHttpBinding, WSHttpBinding, etc) which have a way to expose metadata about itself (WSDL or Mex) with information about all the operations/ parameters in the endpoint, there's currently no standard way to expose metadata for a non-SOAP endpoint - and that's exactly what the webHttpBinding-based endpoints are. In short, the WCF Test Client won't be useful for web-based endpoints. If some standard for representing web-style endpoints emerges when WCF ships its next version, we'll likely update the test client to support it, but for now there's none widely adopted.

+0

@ stimpy77,我简单地引用了MS员工的链接答案。在WCF中,绑定被称为[WebHttpBinding](http://msdn.microsoft.com/en-us/library/system.servicemodel.webhttpbinding.aspx),在WSDL 2中,它被称为[HTTP绑定](http:/ /www.w3.org/TR/wsdl20-adjuncts/#http-binding),但从上下文中可以清楚地看到“基于web”的含义。术语REST不仅仅是通过HTTP公开方法。这是关于将资源视为资源并使用HTTP动词等。请参阅[理查森成熟度模型](http://martinfowler.com/articles/richardsonMaturityModel.html)。 – 2011-05-10 17:35:27

0

我觉得你的配置是不对的,你应该添加节点的安全模式= “none” 和属性bindingConfiguration = “NoneSecurity”

更改为我的配置,再试一次:

<system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="NoneSecurity" 
      maxBufferPoolSize="12000000" maxReceivedMessageSize="12000000" useDefaultWebProxy="false"> 
      <readerQuotas maxStringContentLength="12000000" maxArrayLength="12000000"/> 
      <security mode="None"/> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="Elong.GlobalHotel.Host.IHotelAPIBehavior" 
     name="Elong.GlobalHotel.Host.IHotelAPI"> 
     <endpoint address="" binding="wsHttpBinding" bindingConfiguration="NoneSecurity" contract="Elong.GlobalHotel.Host.IIHotelAPI"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="Elong.GlobalHotel.Host.IHotelAPIBehavior"> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
0
I had a similar problem, the solution was in a minor error in the message alias ... that very generic message ... in our case was assigned a Boolean false if the right is true. 
    This value was in the MDM application that was running on websphere. 

在我的情况的路径:

/opt/infamdm/hub/server/resources/cmxserver.properties 
    /opt/infamdm/hub/cleanse/resources/cmxcleanse.properties