2009-03-02 8 views
5

Viene visualizzato un errore quando si tenta di utilizzare il client di test WCF con il servizio WCF. Ecco il codice di servizio:Errore client test WCF: impossibile richiamare il servizio

[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> 

sono in grado di connettersi al servizio utilizzando il client di prova WCF, ma quando provo a richiamare GetEmployee (employeeNumber) ottengo il seguente errore:

Impossibile invocare il servizio. Possibili cause: il servizio è offline o inaccessibile; la configurazione lato client non corrisponde al proxy; il proxy esistente non è valido. Fare riferimento alla traccia dello stack per ulteriori dettagli. È possibile provare a ripristinare avviando un nuovo proxy, ripristinando la configurazione predefinita o aggiornando il servizio.

Sono riuscito a chiamare questo servizio inviando una richiesta dal browser.

Qualche idea sul motivo per cui non riesco a utilizzare il client di test WCF?

risposta

11

Si prega di ignorare la mia risposta precedente. Non penso che il problema sia nella configurazione lato client.

Vedere 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, ho semplicemente citato dalla risposta collegata da un dipendente di MS. In WCF, il binding si chiama [WebHttpBinding] (http://msdn.microsoft.com/en-us/library/system.servicemodel.webhttpbinding.aspx) e in WSDL 2, si chiama [binding HTTP] (http://www.w3.org/TR/wsdl20-adjuncts/#http-binding), ma è abbastanza chiaro dal contesto cosa significa "web-based" qui. Il termine REST va ben oltre la semplice esposizione dei metodi via HTTP. Si tratta di trattare le cose come risorse e usare i verbi HTTP ecc. Vedi [Richardson Maturity Model] (http://martinfowler.com/articles/richardsonMaturityModel.html). –

0

Penso che il vostro config è sbagliato, si dovrebbe aggiungere la modalità di protezione nodo = "Nessuno" e attribuire bindingConfiguration = "NoneSecurity"

Change come il mio config, riprova:

<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. 

il percorso nel mio caso:

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