简体   繁体   中英

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

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>

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM