Consuming a WCF service - c#, VS2008 with 3.5 SP1

杀马特。学长 韩版系。学妹 提交于 2020-01-03 03:22:06

问题


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");

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."

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.com/Service.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISearchService"
            contract="ServiceReference1.ISearchService" name="BasicHttpBinding_ISearchService" />
    </client>

回答1:


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

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.

Example <serviceBehaviors> tag:

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

Example of specifying the service behavior:

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

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




回答2:


If you can modify the configuration file on the server here's what you can do to get the exception information through the service.

You need to add a service behavior section to the server's config.

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

Then associate the service with that behavior.

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


来源:https://stackoverflow.com/questions/858157/consuming-a-wcf-service-c-vs2008-with-3-5-sp1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!