2009-03-02 135 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 
相關問題