Protobuf-net返回类型List <t>为null </t>

时间:2013-08-20 04:03:08

标签: wcf protobuf-net

我正在尝试将我的服务配置为使用protobuf-net。返回T []和T的方法有效但List返回null。是否支持?

另外,我怎么能告诉它在序列化过程中确实使用了protobuf。我试图使用小提琴手,但我无法区分它们。

public interface IOrdersService
{        
    [OperationContract(IsOneWay = false)]
    OrderDTO[] GetAllOrders();

    [OperationContract(IsOneWay = false)]
    List<OrderDTO> GetAllOrders2();

    [OperationContract(IsOneWay = false)]
    OrderDTO GetOrder();
}

public class OrdersClient : IOrdersServiceCallback
{
    private OrdersServiceClient client;

    public OrdersClient()
    {

    }

    public void Init()
    {
        InstanceContext site = new InstanceContext(null, new OrdersClient());
        client = new OrdersServiceClient(site);
    }

    public void Start()
    {
        OrderDTO[] orders = client.GetAllOrders();

        OrderDTO[] orders2 = client.GetAllOrders2();

        OrderDTO dto = client.GetOrder();
        Console.WriteLine(dto);
    }        
}

web config

<?xml version="1.0"?>
<configuration>

<system.web>
  <compilation debug="true" targetFramework="4.5" />
  <httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
  <services>
    <service name="OrdersServer.OrdersService">
      <endpoint address=""
                binding="wsDualHttpBinding" 
                bindingConfiguration="Binding1"
                contract="OrdersServer.IOrdersService"                  
                behaviorConfiguration="ProtoBufBehavior" />
    </service>
  </services>
  <bindings>
    <wsDualHttpBinding>
      <binding name="Binding1">
        <!-- Binding property values can be modified here. -->
        <security mode="None"/>
      </binding>
    </wsDualHttpBinding>
  </bindings>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
        <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
        <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
      <behavior name="ProtoBufBehavior">
        <protobuf />
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <protocolMapping>
      <!--add binding="basicHttpsBinding" scheme="https" />-->
      <add scheme="http" binding="wsDualHttpBinding"/>
  </protocolMapping>    
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  <extensions>
    <behaviorExtensions>
      <add name="protobuf" type="ProtoBuf.ServiceModel.ProtoBehaviorExtension, protobuf-net, Version=2.0.0.640, Culture=neutral, PublicKeyToken=257b51d87d2e4d67"/>
    </behaviorExtensions>
  </extensions>
</system.serviceModel>
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
  <!--
      To browse web app root directory during debugging, set the value below to true.
      Set to false before deployment to avoid disclosing web app folder information.
    -->
  <directoryBrowse enabled="true"/>
</system.webServer>

</configuration>

客户端配置

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <bindings>
            <wsDualHttpBinding>
                <binding name="WSDualHttpBinding_IOrdersService" clientBaseAddress="http://localhost:8000/whatisthis/">
                    <security mode="None" />
                </binding>
            </wsDualHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost.fiddler:49522/OrdersService.svc"
            binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IOrdersService"
            contract="OrdersServiceReference.IOrdersService" name="WSDualHttpBinding_IOrdersService"
                   behaviorConfiguration="proto"/>
        </client>
        <behaviors>
          <endpointBehaviors>
            <behavior name="proto">
              <protobuf />
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <extensions>
          <behaviorExtensions>
            <add name="protobuf" type="ProtoBuf.ServiceModel.ProtoBehaviorExtension, protobuf-net, Version=2.0.0.640, Culture=neutral, PublicKeyToken=257b51d87d2e4d67"/>
          </behaviorExtensions>
        </extensions>
    </system.serviceModel>
</configuration>

0 个答案:

没有答案
相关问题