5

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

4

3 回答 3

11

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

请参阅WCF 测试客户端和 WebHttpBinding

这是 Web 编程模型本身的限制。与 SOAP 端点(即具有 BasicHttpBinding、WSHttpBinding 等的端点)不同,SOAP 端点(即具有 BasicHttpBinding、WSHttpBinding 等的端点)可以通过端点中所有操作/参数的信息来公开有关自身的元数据(WSDL 或 Mex),目前没有标准方法来公开元数据非 SOAP 端点——这正是基于 webHttpBinding 的端点。简而言之,WCF 测试客户端对基于 Web 的端点没有用处。如果 WCF 发布下一个版本时出现了一些表示 Web 样式端点的标准,我们可能会更新测试客户端以支持它,但目前还没有被广泛采用。

于 2009-03-04T07:52:45.640 回答
0

我认为你的配置是错误的,你应该添加节点安全模式=“无”和属性绑定配置=“无安全”

更改为我的配置,再试一次:

<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>
于 2012-11-29T05:17:25.457 回答
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
于 2014-10-30T09:09:19.900 回答