![](/img/trans.png)
[英]This operation is not supported in wcf test client because it uses system.threading.tasks.task
[英]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" />
它会解决您的问题。
要么
您也可以删除以上键并尝试(供参考)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.