Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Test Client error: Failed to Invoke the service

I'm getting an error when trying to use the WCF Test Client with my WCF service. Here is the service code:

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

I am able to connect to the service using the WCF Test Client, but when I try to invoke GetEmployee(employeeNumber) I get the following error:

Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.

I was able to successfully call this service by sending a request from the browser.

Any idea why I can't use the WCF Test Client?

like image 662
Kevin Babcock Avatar asked Mar 02 '09 21:03

Kevin Babcock


1 Answers

Please ignore my earlier answer. I don't think the problem is at the client-side config.

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

like image 180
Eugene Yokota Avatar answered Sep 28 '22 04:09

Eugene Yokota