1

I am very new to WCF service. I want to write WCF web service and I am following tutorials. It seems I can't get to write anything as I am getting this error all the time:

This operation is not supported in the wcf test client because it uses type System.Threading..

I created a basic WCF Library Project which comes with a default code as follows:

IService1.cs:

namespace WCFandEFService
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);
    }

    [DataContract]
    public class CompositeType
    {
        [DataMember]
        public bool BoolValue { get; set; }

        [DataMember]
        public string StringValue { get; set; }
    }
}

and Service1.cs:

namespace WCFandEFService
{
    public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }

            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }

            return composite;
        }
    }
}

app.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.serviceModel>
    <services>
      <service name="WCFandEFService.Service1">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8733/Design_Time_Addresses/WCFandEFService/Service1/" />
          </baseAddresses>
        </host>
        <endpoint address="" binding="basicHttpBinding" contract="WCFandEFService.IService1">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

After Ctrl-F5 it says your service have been hosted. But I encounter the error.

Why is this happening?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
linda
  • 19
  • 7
  • It happens because the WCF Test Client is severely limited. Try writing your own WCF client and consume the service - there's a good chance it'll work. But on the other hand: you should try to avoid passing around specific types like `System.Thread` - WCF services strive to be **interoperable**, and a Ruby or PHP client will definitely not know how to handle a .NET `System.Thread` type ... – marc_s Sep 22 '14 at 18:47
  • @marc_s I will try, thanks. Actually I am considering to use WCF web service from Objective C (IPhone app). And, don't know where am i passing System.Thread here though.. – linda Sep 22 '14 at 19:21

1 Answers1

0

Set below key value to false as it is using threading internally.

<add key="aspnet:UseTaskFriendlySynchronizationContext" value="false" />

it will get your problem solved.

or

you can remove also above key as well and try (For your information)

What's the meaning of "UseTaskFriendlySynchronizationContext"?

Community
  • 1
  • 1
Ashok Rathod
  • 840
  • 9
  • 24