0

I'm not fluent in WCF Services so I'm struggling to return XmlElement as the return type.

I'm getting the message from the WCF Test Client (running in debug mode):

The operation is not supported from the wcf test client because it uses type XmlElement.

[ServiceContract]
public interface IClientService
{

    [OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Xml)]
    XmlElement GetClientXml(int value);

}

namespace testWCF
{
    public class testSvc: IClientService
    {

        public XmlElement GetClientXml(int value)
        {
            string appDir = AppContext.BaseDirectory;
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(appDir + @"Xml\ResponseTempl.xml");
            return xDoc.DocumentElement;
        }

    }
}

I've referred to this as well but it might be too old, as I'm using 4.6.1 framework: Returning XML From a WCF Service

my Web.Debug.config file :

<?xml version="1.0" encoding="utf-8"?>

<!-- For more information on using web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>    
  </system.web>

  <system.serviceModel>
    <services>
      <service name="AucklandRegionalPatientWCF.PatientDemographicService" >

        <!-- these endpoint are necessary to return SOAP service -->
        <endpoint address=""
                     binding="basicHttpBinding"
                     contract="AucklandRegionalPatientWCF.IPatientDemographicService" />
        <endpoint address="mex"
                  contract="IMetadataExchange" binding="mexHttpBinding"/>

        <!-- REST service return xml -->
        <!--To call this endpoint use: [service].svc/xml/[method_Name]-->
        <endpoint address="xml"
                  binding="webHttpBinding" behaviorConfiguration="xmlBehavior"
                  contract="AucklandRegionalPatientWCF.IPatientDemographicService" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          
          <serviceMetadata httpGetEnabled="true"/>
          
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>

      <endpointBehaviors>
        <!-- use XML serialization -->
        <behavior name="xmlBehavior">
          <webHttp/>          
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
</configuration>

WCF Test Client

bob.mazzo
  • 5,183
  • 23
  • 80
  • 149
  • It's not entirely clear from the code you've shared what's happening. You have an interface `IClientService`, and then a class implementing or inheriting from `TestSvc`. Where's the code for the "Test Client"? – Heretic Monkey Feb 06 '18 at 17:51
  • @MikeMcCaughan - I'm running debug mode in vs2017, testing the service via the WCF Test Client interface. – bob.mazzo Feb 06 '18 at 18:18
  • The error message is pretty clear. WCF TestClient doesn't support `XmlElement`. You'll need to write your own test harness (e.g., console app) to test it. See https://stackoverflow.com/a/8568078/745969 for a list of what WCF Test Client does not support. – Tim Feb 06 '18 at 18:33
  • Okay, I understand now that it's the test client itself that doesn't support xml. – bob.mazzo Feb 06 '18 at 18:40
  • Possible duplicate of [WCF service method unavailable in WCF Test Client because it uses type](https://stackoverflow.com/questions/8567849/wcf-service-method-unavailable-in-wcf-test-client-because-it-uses-type) – Tim Feb 07 '18 at 01:05

1 Answers1

1

Best way to get XML element from WCf as response use XML formatted string.. Best at performance as well as light weight..... Create response class and use XML serialization.... It will be helpful