gpt4 book ai didi

WCF 测试客户端错误 : Failed to Invoke the service

转载 作者:行者123 更新时间:2023-12-04 17:14:13 27 4
gpt4 key购买 nike

尝试将 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 测试客户端吗?

最佳答案

请忽略我之前的回答。我不认为问题出在客户端配置上。

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.

关于WCF 测试客户端错误 : Failed to Invoke the service,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/604020/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com