0

我收到此错误:

没有模型实例被分配给 ProtoOperationBehavior

我刚刚在 Visual Studio 中使用了 WCF 模板应用程序来查看是否可以运行它。如何修复此错误?

代码

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

[ServiceContract]
public interface IService1
{

    [OperationContract]
    [ProtoBehavior()]
    string GetData(int value);

    [OperationContract]
    [ProtoBehavior()]
    CompositeType GetDataUsingDataContract(CompositeType composite);
}


[DataContract]
[ProtoBuf.ProtoContract]
public class CompositeType
{
    bool boolValue = true;
    string stringValue = "Hello ";

    [DataMember(Order = 1)]
    [ProtoBuf.ProtoMember(1)]
    public bool BoolValue
    {
        get { return boolValue; }
        set { boolValue = value; }
    }

    [DataMember(Order = 2)]
    [ProtoBuf.ProtoMember(2)]
    public string StringValue
    {
        get { return stringValue; }
        set { stringValue = value; }
    }
}

应用程序配置:

<services> 
<service name="ProtoBufService.Service1"> 
    <host> 
        <baseAddresses> 
            <add baseAddress="net.tcp://localhost:9086/ProtoBufService/Service1/" />
        </baseAddresses>
    </host> 
    <endpoint address="basic" 
        binding="netTcpBinding" contract="ProtoBufService.IService1" 
        behaviorConfiguration="protoEndpointBehavior">         
    </endpoint> 
    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>     
</service> 
</services>
<extensions> 
    <behaviorExtensions> 
         <add name="protobuf" 
            type="ProtoBuf.ServiceModel.ProtoBehaviorExtension, 
            protobuf-net, Version=2.0.0.640, 
            Culture=neutral, PublicKeyToken=257b51d87d2e4d67" />     
     </behaviorExtensions> 
</extensions>

<endpointBehaviors>
    <behavior name="protoEndpointBehavior">
        <protobuf />
    </behavior>
</endpointBehaviors>
4

1 回答 1

0

I tried using nuget. That did not work.

I would love to hear more about what problems you had there

I then tried to use the google code version (Core, net30 assembly), same error.

The "core only" library does not include the meta-programming layer - it is designed for use with pre-generated serialization assemblies. As such, there is no default model - one must always be provided.

The simplest "fix" here is simply to use the "full" build of the library; this has the meta-programming model as a default model.

于 2013-06-19T22:37:02.610 回答