尝试将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测试客户端吗?
答案 0 :(得分:11)
请忽略我之前的回答。我认为问题不在于客户端配置。
请参阅WCF Test Client and WebHttpBinding。
这是网络的限制 编程模型本身。与SOAP不同 端点(即那些有端点的端点) BasicHttpBinding,WSHttpBinding等) 哪种方法可以公开元数据 关于自己(WSDL或Mex) 有关所有操作的信息/ 有端点的参数 目前没有标准的曝光方式 非SOAP端点的元数据 - 和 那正是如此 基于webHttpBinding的端点是。在 简而言之,WCF测试客户端不会 对基于Web的端点很有用。如果 代表的一些标准 WCF时会出现Web样式的端点 发布它的下一个版本,我们很可能 更新测试客户端以支持它, 但目前还没有广泛的 通过。
答案 1 :(得分:0)
我认为你的配置错了,你应该添加node security mode =“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>
答案 2 :(得分: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