【问题标题】:WCF error message - method <name> not supported on ProxyWCF 错误消息 - 代理不支持方法 <名称>
【发布时间】:2015-05-07 15:23:33
【问题描述】:

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

我遇到了以下错误消息 " 此代理不支持 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>

来自所有功能。现在我的代码有点脏,但运行良好

为什么会出现这个错误信息?

【问题讨论】:

  • 如果您发布解决方案,我们或许可以告诉您为什么会发生这种情况。否则就是猜谜游戏。

标签: c# wcf


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2021-06-17
    • 2021-12-23
    • 2011-04-04
    • 1970-01-01
    • 2019-05-05
    • 1970-01-01
    • 2017-02-26
    • 1970-01-01
    • 2019-12-11
    相关资源
    最近更新 更多