WCF 服务:无法通过“WebHttpBinding"端点调用方法 [英] WCF service: Can't call methods through the 'WebHttpBinding' endpoint

查看:32
本文介绍了WCF 服务:无法通过“WebHttpBinding"端点调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了 WCF 服务,这是它的配置部分:

I've created WCF service, here is it's configuration section:

<system.serviceModel>
<services>
  <service name="McActivationApp.EnrollmentService" behaviorConfiguration="McActivationApp.EnrollmentServicBehavior">
    <endpoint address="" binding="webHttpBinding" contract="McActivationApp.IEnrollmentService"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="McActivationApp.IEnrollmentService" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="McActivationApp.EnrollmentServicBehavior">
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

我使用 WcfTestClient 连接到服务,添加了服务并且只能调用IEnrollmentService (MetadataExchangeHttpBinding_IEnrollmentService)"部分中的方法(它们按预期工作).

I connected to the service with WcfTestClient, added service and can call only methods that are in "IEnrollmentService (MetadataExchangeHttpBinding_IEnrollmentService)" section (they work as expected).

但是来自另一部分IEnrollmentService (WebHttpBinding_IEnrollmentService)"的方法不可调用.当我尝试调用其中任何一个时,我收到以下错误:

But methods from another section "IEnrollmentService (WebHttpBinding_IEnrollmentService)" are not callable. When I try to call any of them I receives 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.

错误详情:

The Address property on ChannelFactory.Endpoint was null.  The ChannelFactory's Endpoint must have a valid Address specified.
   at System.ServiceModel.ChannelFactory.CreateEndpointAddress(ServiceEndpoint endpoint)
   at System.ServiceModel.ChannelFactory`1.CreateChannel()
   at System.ServiceModel.ClientBase`1.CreateChannel()
   at System.ServiceModel.ClientBase`1.CreateChannelInternal()
   at System.ServiceModel.ClientBase`1.get_Channel()
   at EnrollmentServiceClient.UpdateEnrollmentProfile(String enrollmentId, String siteName, String deployServerName, Int32 methodId, String deviceClass, String deviceName, String registrationCode)

问题 1:我是否正确理解,对于调用IEnrollmentService (WebHttpBinding_IEnrollmentService)"方法的情况,我需要另外指定一些端点?

Question 1: Am I correctly understand that for case of "IEnrollmentService (WebHttpBinding_IEnrollmentService)" methods calling I need to specify additionally some endpoint?

问题 2:我能做到吗?

问题 3:我应该关心它们吗(因为我将能够从我的自定义"应用程序中调用方法)?

Question 3: Should I care about them (as I will be able to call methods from my 'custom' application)?

推荐答案

谢谢大家的回答,他们让我思考了一些问题.以下是我的问题的答案:

Thank you, guys, for your answers, they gave me some food to think. Here are answers on my questions:

答案 1:

实际上,正如marc_s"所述,问题在于我的服务被配置为REST"服务,因此答案是是",以便让 WcfTestClient 应用程序附加端点(basicHttpBinding)可以访问这些服务是必需的.

Actually, as is stated by "marc_s" the problem is that my service was configured as 'REST' service, so answer is "Yes" to get those services accessible for WcfTestClient application additional endpoint (basicHttpBinding) is required.

答案 2:

正如answer1"中所述:是的,要使其可行,您需要添加 basicHttpBinding 端点.

As is stated in "answer1": yes, to get it workable you need to add basicHttpBinding endpoint.

答案 3:

这取决于.如果您不打算使用 WcfTestClient 进行测试"——请不要在意.在我的特殊情况下,我将实施单元测试来检查方法调用结果,因此 WcfTestClient 中的可操作性并不重要.

It depends. If you don't plan to do 'testing' with WcfTestClient - don't care. In my particular case I will implement unit tests to check method call results, so workability in WcfTestClient not important.

感谢您并为每个有用的答案+1".

Thanks you and "+1" for each helpful answer.

附言我接受自己的答案的原因是这与问题(对我来说必不可少)一致.

P.S. The reason why I've accepted own answer is that is consistent with questions (that are essential for me).

这篇关于WCF 服务:无法通过“WebHttpBinding"端点调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆