WCF 错误消息 - 代理不支持方法 <name>

WCF error message - method <name> not supported on Proxy

事实上我已经找到了解决问题的方法,但我只是好奇。

我遇到了以下错误消息 “此代理不支持方法 UnlockObject。如果方法未标记为 OperationContractAttribute 或接口类型未标记为 ServiceContractAttribute,则可能发生这种情况

这是我的界面:

[ServiceContract(CallbackContract = typeof(IServeurCallback), SessionMode.Required)]
public interface IServeur
{
   [OperationContract(IsOneWay = true)]
   void UnlockObject<T>(Guid ClientId, ObjectId toUnlock, string collectionName);
   [...]
}

它是如何在我的服务器中实现的

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class Serveur : Proxy.IServeur
{
   public void UnlockObject<T>(Guid ClientId, ObjectId toUnlock, string collectionName)
   {
      /*stuff using <T>*/
   }
}

以及我的客户如何调用它

if (this.comboBox1.SelectedItem.ToString() == "Projet")
    this.channel.UnlockObject<ProjectClass.Project>(client._Guid, toSend, "collection_Project");
else if (this.comboBox1.SelectedItem.ToString() == "Object")
    this.channel.UnlockObject<Object.c_Object>(client._Guid, toSend, "collection_Object");
else if (this.comboBox1.SelectedItem.ToString() == "ObjString")
    this.channel.UnlockObject<ObjString.ObjString>(client._Guid, toSend, "collection_ObjString");

(this.channel 是这样创建的

 DuplexChannelFactory<Proxy.IServeur> factory;
 /* do stuff to make it usable */
 Proxy.IServeur channel = factory.CreateChannel();

我通过删除

解决了这个问题
<T>

来自所有功能。现在我的代码有点脏,但它工作正常

为什么会出现此错误消息?

您有例外,因为 wsdl 不支持开放泛型类型,因此 WCF 服务无法在操作合同中公开它们,因为它使用 wsdl 来公开您的操作的元数据。

可以在您的代码中公开有界泛型(请参阅 details),或者由于 <T> 参数仅标识类型,您可以将其添加为另一个参数

 [OperationContract(IsOneWay = true)]
 void UnlockObject(Type objectType,Guid ClientId, ObjectId toUnlock, string collectionName);