【问题标题】:Consuming a WCF service - c#, VS2008 with 3.5 SP1使用 WCF 服务 - c#, VS2008 with 3.5 SP1
【发布时间】:2009-05-13 14:05:39
【问题描述】:

我正在尝试使用 WCF 服务。我获得了 svc 文件的 URL。 1.创建一个Windows窗体应用程序 2.添加了对svc文件的服务引用 3.在表单加载事件期间的代码中,我调用了服务公开的方法

        ServiceReference1.SearchServiceClient search = new WindowsFormsApplication1.ServiceReference1.SearchServiceClient();
        var serviceResult = search.SearchByClientNumber("1");

我收到此错误 由于内部错误,服务器无法处理请求。有关错误的更多信息,请在服务器上打开 IncludeExceptionDetailInFaults(来自 ServiceBehaviorAttribute 或来自配置行为)以便将异常信息发送回客户端,或根据 Microsoft .NET Framework 3.0 SDK 文档打开跟踪并检查服务器跟踪日志。”

我可以使用 WCFTestClient 调用该方法,但不能在我的应用程序中调用。

我需要在我的测试应用配置文件中进行一些更改吗?有一个部分

<client>
        <endpoint address="http://somewhere.com/Service.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISearchService"
            contract="ServiceReference1.ISearchService" name="BasicHttpBinding_ISearchService" />
    </client>

【问题讨论】:

  • 两个答案都是相关的并解决了问题。很遗憾 OP 没有完成。

标签: c# visual-studio-2008 wcf


【解决方案1】:

当从服务中抛出异常并且无法返回消息时会发生此错误。

如果您有权访问服务代码,只需按照异常状态执行(“...打开 IncludeExceptionDetailInFaults(来自 ServiceBehaviorAttribute 或来自配置行为)...”)调试。

例如&lt;serviceBehaviors&gt;标签:

<serviceBehaviors>
    <behavior name="WcfService1.Service1Behavior">
        <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
</serviceBehaviors>

指定服务行为的示例:

<service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior">

ServiceBehaviorAttribute.IncludeExceptionDetailInFaults 属性的详细说明可参见here

【讨论】:

    【解决方案2】:

    如果您可以修改服务器上的配置文件,您可以通过服务获取异常信息。

    您需要在服务器的配置中添加一个服务行为部分。

    <behaviors>
      <serviceBehaviors>
        <behavior name="serviceNameBehavior">
          <serviceDebug includeExceptionDetailInFaults="True" />
          </behavior>
      </serviceBehaviors>
    </behaviors>
    

    然后将服务与该行为相关联。

    <service name="serviceName" behaviorConfiguration="serviceNameBehavior" ...
    

    【讨论】:

    • 我认为应该是 标签中的“behaviorConfiguration”而不是“behavior”。
    猜你喜欢
    • 2010-11-09
    • 2010-09-10
    • 1970-01-01
    • 2010-09-08
    • 1970-01-01
    • 1970-01-01
    • 2011-09-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多