使用 WCF 服务

编程入门 行业动态 更新时间:2024-10-18 12:33:25
本文介绍了使用 WCF 服务 - c#, VS2008 with 3.5 SP1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

I am trying to cnsume a WCF service.I was given the URL to the svc file. 1. Created a Windows form application 2. Added a service reference to the svc file 3. In my code behind during form load event, i call the method exposed by service

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

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

I get this error The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs."

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

I can invoke the method using WCFTestClient but not in my application.

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

Is there some change that i need to perform in my test app config file? There is a section for

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

推荐答案

当从服务内部抛出异常并且无法返回消息时,会发生此错误.

This error occurs when an exception is thrown from within the service and the message cannot be returned.

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

If you have access to the service code, just do as the exception states ("... turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) ...") in order to debug.

示例 标签:

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

指定服务行为的示例:

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

ServiceBehaviorAttribute.IncludeExceptionDetailInFaults 属性的详细描述可以在 这里.

Detailed description of the ServiceBehaviorAttribute.IncludeExceptionDetailInFaults property can be found here.

这篇关于使用 WCF 服务 - c#, VS2008 with 3.5 SP1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-27 12:07:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1154858.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:WCF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!