C# WCF错误消息-方法<;名称>;代理服务器上不支持
事实上,我已经找到了解决问题的办法,但我只是好奇 我遇到了以下错误消息 “此代理不支持方法UnlockObject。如果该方法未标记为OperationContractAttribute或接口类型未标记为ServiceContractAttribute,则可能发生此情况” 这是我的界面:C# WCF错误消息-方法<;名称>;代理服务器上不支持,c#,wcf,C#,Wcf,事实上,我已经找到了解决问题的办法,但我只是好奇 我遇到了以下错误消息 “此代理不支持方法UnlockObject。如果该方法未标记为OperationContractAttribute或接口类型未标记为ServiceContractAttribute,则可能发生此情况” 这是我的界面: [ServiceContract(CallbackContract = typeof(IServeurCallback), SessionMode.Required)] public interface ISe
[ServiceContract(CallbackContract = typeof(IServeurCallback), SessionMode.Required)]
public interface IServeur
{
[OperationContract(IsOneWay = true)]
void UnlockObject<T>(Guid ClientId, ObjectId toUnlock, string collectionName);
[...]
}
[ServiceContract(CallbackContract=typeof(iservourcallback),SessionMode.Required]
公共接口IServer
{
[运营合同(IsOneWay=true)]
void UnlockObject(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>*/
}
}
[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall,ConcurrencyMode=ConcurrencyMode.Multiple)]
公共类服务器:Proxy.IServeur
{
public void unlock对象(Guid ClientId、ObjectId toUnlock、string collectionName)
{
/*使用*/
}
}
我的客户是怎么称呼它的
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");
if(this.comboBox1.SelectedItem.ToString()=“Projet”)
this.channel.UnlockObject(客户端.u Guid,toSend,“集合项目”);
else if(this.comboBox1.SelectedItem.ToString()=“Object”)
this.channel.UnlockObject(客户机.u Guid,toSend,“集合\u对象”);
else if(this.comboBox1.SelectedItem.ToString()=“ObjString”)
this.channel.UnlockObject(client.u Guid,toSend,“collection\u ObjString”);
(此.channel是这样创建的
DuplexChannelFactory<Proxy.IServeur> factory;
/* do stuff to make it usable */
Proxy.IServeur channel = factory.CreateChannel();
duplexchannel工厂;
/*做一些事情使它可用*/
Proxy.IServeur channel=factory.CreateChannel();
我通过移除
<T>
现在我的代码有点脏了,但它工作得很好
为什么会显示此错误消息?您有异常,因为
wsdl
不支持开放泛型类型,因此WCF
服务无法在操作契约上公开它们,因为它使用wsdl
来公开操作的元数据
可以在代码中公开有界泛型(请参阅),或者由于
参数仅标识类型,因此可以将其添加为另一个参数
[OperationContract(IsOneWay = true)]
void UnlockObject(Type objectType,Guid ClientId, ObjectId toUnlock, string collectionName);
如果你发布解决方案,我们可能会告诉你为什么会发生。否则这只是一个猜测游戏。