簡體   English   中英

創建WCF服務時出錯:WCF測試客戶端不支持此操作,因為它使用類型System.Threading

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

我是WCF服務的新手。 我想編寫WCF Web服務,並且正在關注教程。 似乎我無法寫任何東西,因為我一直都在收到此錯誤:

wcf測試客戶端不支持此操作,因為它使用類型System.Threading ..

我創建了一個基本的WCF庫項目,該項目帶有以下默認代碼:

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; }
    }
}

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文件:

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

Ctrl-F5之后 ,表示您的服務已托管 但是我遇到了錯誤。

為什么會這樣呢?

將下面的鍵值設置為false,因為它在內部使用線程。

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

它會解決您的問題。

要么

您也可以刪除以上鍵並嘗試(供參考)

“ UseTaskFriendlySynchronizationContext”是什么意思?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM