简体   繁体   中英

Error in creating WCF service: this operation is not supported in the wcf test client because it uses type System.Threading

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?

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

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