protobuf-net WCF配置问题

时间:2013-12-23 23:44:44

标签: protobuf-net

我正在尝试在我们的WCF服务中加入protobuf-net序列化。 我找到了所有文章/教程并遵循了所有说明,但我的示例项目似乎总是使用默认的datacontractserializer。

我确信我错过了一些东西。

我甚至从protobuf-net网站下载了共享DTO样本。

有人能够解决一些问题吗?

下面是web.config,然后是app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>

    <system.serviceModel>
      <behaviors>
        <endpointBehaviors>
          <behavior name="proto">
            <protobuf />
          </behavior>
        </endpointBehaviors>
      </behaviors>
      <extensions>
        <behaviorExtensions>
          <add name="protobuf" type="ProtoBuf.ServiceModel.ProtoBehaviorExtension, protobuf-net" />
        </behaviorExtensions>
      </extensions>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IWcfService" maxReceivedMessageSize="2147483647" />
                <binding name="BasicHttpBinding_IService1" closeTimeout="00:10:00"
                    openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
                    allowCookies="false" bypassProxyOnLocal="false" maxBufferPoolSize="2147483647"
                    maxReceivedMessageSize="2147483647" useDefaultWebProxy="true"  />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://houngoduguw7/ProtoBuf.Service/Service1.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
                contract="ProtofBuf.IService1" name="BasicHttpBinding_IService1" behaviorConfiguration="proto"/>
            <endpoint address="http://houngoduguw7/Wcf.Service/WcfService1.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWcfService"
                contract="Wcf.IWcfService" name="BasicHttpBinding_IWcfService" />
        </client>
    </system.serviceModel>
</configuration>


<?xml version="1.0" encoding="UTF-8"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
        <listeners>
          <add name="ServiceModelTraceListener" />
        </listeners>
      </source>
      <source name="System.ServiceModel" switchValue="Verbose,ActivityTracing">
        <listeners>
          <add name="ServiceModelTraceListener" />
        </listeners>
      </source>
      <source name="System.Runtime.Serialization" switchValue="Verbose,ActivityTracing">
        <listeners>
          <add name="ServiceModelTraceListener" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="App_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp" />
    </sharedListeners>
  </system.diagnostics>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.serviceModel>

    <extensions>
      <behaviorExtensions>
        <add name="protobuf" type="ProtoBuf.ServiceModel.ProtoBehaviorExtension, protobuf-net" />
      </behaviorExtensions>
    </extensions>
    <behaviors>
      <endpointBehaviors>
        <behavior name="proto">
          <protobuf />
        </behavior>
      </endpointBehaviors>
      <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>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
      <service name="ProtoBuf.Service.Service1">
        <endpoint address="proto" binding="basicHttpBinding" 
         contract="ProtoBuf.Service.IService1" behaviorConfiguration="proto" />


      </service>
    </services>
  </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" />
    <security>
      <authentication>
        <anonymousAuthentication enabled="true" />
        <windowsAuthentication enabled="false" />
      </authentication>
    </security>
  </system.webServer>

</configuration>

1 个答案:

答案 0 :(得分:0)

我能够找到解决方案。我试图序列化的类是根接口类型,它们没有正确序列化。