views:

2606

answers:

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

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>
+4  A: 

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.

Steve Dignan
+1  A: 

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" ...
Antonio Haley
I think it should be "behaviorConfiguration" instead of "behavior" within the <service> tag.
Steve Dignan
yep, you caught me, fixed
Antonio Haley
A: 

Thanks for this!!!