Protobuf.net和WCF自主获取空请求?

时间:2012-08-24 09:25:18

标签: .net wcf iis protobuf-net self-hosting

我有一个WCF服务,我在IIS7中作为主机托管,并且使用默认的serlizer,它在两者中都很好。

运行protobuf.net端点时,它可以很好地对抗IIS7主机,但是当针对自我主机运行时,我只是将第一个服务方法作为请求获取?

我应该在哪里看?你需要什么帮助我解决这个问题?

BestRegards

Edit1:App.config(selfhost)

    <system.serviceModel>
  <diagnostics>
    <messageLogging logEntireMessage="true" logMalformedMessages="true"
      logMessagesAtTransportLevel="true" />
  </diagnostics>
  <extensions>
    <behaviorExtensions>
      <add name="protobuf" type="ProtoBuf.ServiceModel.ProtoBehaviorExtension, protobuf-net, Version=2.0.0.480, Culture=neutral, PublicKeyToken=257b51d87d2e4d67"/>
      <add name="customBehaviorExtension_Integration" type="MyApp.ServiceImplementation.CustomRequestInterceptorBehaviorExtension_Integration, MyApp.ServiceImplementation"/>
      <add name="customBehaviorExtension_ClientService" type="MyApp.ServiceImplementation.CustomRequestInterceptorBehaviorExtension_ClientService, MyApp.ServiceImplementation"/>
    </behaviorExtensions>
  </extensions>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
  <behaviors>
    <serviceBehaviors>
      <behavior name="MyApp.ServiceImplementation.MyAppIntegration_Behavior">
        <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
        <serviceMetadata httpGetEnabled="true"/>
        <customBehaviorExtension_Integration/>
      </behavior>
      <behavior name="MyAppClientService.CustomValidator_Behavior">
        <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
        <serviceMetadata httpGetEnabled="true"/>
        <customBehaviorExtension_ClientService/>
        <serviceThrottling maxConcurrentCalls="2000" maxConcurrentSessions="2147483647" maxConcurrentInstances="2000"/>
        <serviceCredentials>
          <clientCertificate>
            <authentication certificateValidationMode="PeerOrChainTrust"/>
          </clientCertificate>
          <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyApp.ServiceImplementation.CustomUsernamePasswordValidator, MyApp.ServiceImplementation"/>
        </serviceCredentials>
        <serviceAuthorization principalPermissionMode="Custom" serviceAuthorizationManagerType="MyApp.ServiceImplementation.CustomServiceAuthorizationManager, MyApp.ServiceImplementation">
          <authorizationPolicies>
            <add policyType="MyApp.ServiceImplementation.CustomAuthorizationPolicy_ClientService, MyApp.ServiceImplementation"/>
          </authorizationPolicies>
        </serviceAuthorization>
      </behavior>
      <behavior name="MyApp.ServiceImplementation.HL7Service_Behavior">
        <serviceDebug includeExceptionDetailInFaults="true"/>
        <serviceMetadata httpGetEnabled="true" externalMetadataLocation="..\Schema\HL7\DIPS\IHl7Service.wsdl"/>
        <customBehaviorExtension_Integration/>
      </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
      <behavior name="protoEndpointBehavior">
        <protobuf/>
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <services>
    <service behaviorConfiguration="MyApp.ServiceImplementation.MyAppIntegration_Behavior" name="MyApp.ServiceImplementation.MyAppIntegration">
      <endpoint binding="basicHttpBinding" bindingConfiguration="BasicMyAppIntegration" bindingNamespace="MyApp.ServiceImplementation" contract="MyApp.ServiceContracts.IMyAppIntegration"/>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8003/MyApp5Service/Integration"/>
        </baseAddresses>
      </host>
    </service>
    <service behaviorConfiguration="MyAppClientService.CustomValidator_Behavior" name="MyApp.ServiceImplementation.MyAppClientService">
      <endpoint binding="netTcpBinding" bindingConfiguration="netTcpRegular" address="Regular" bindingNamespace="http://MyApp.ServiceContracts/2007/11" contract="MyApp.ServiceContracts.IMyAppClientService"/>
      <endpoint binding="netTcpBinding" behaviorConfiguration="protoEndpointBehavior" bindingConfiguration="netTcpRegular" address="Proto" bindingNamespace="http://MyApp.ServiceContracts/2007/11" contract="MyApp.ServiceContracts.IMyAppClientService"/>

      <endpoint binding="netTcpBinding" bindingConfiguration="netTcpWindowMessageSecurity" address="Windows" bindingNamespace="http://MyApp.ServiceContracts/2007/11" contract="MyApp.ServiceContracts.IMyAppClientService"/>
      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://localhost:8001/MyApp5Service/Client/"/>
          <add baseAddress="http://localhost:8002/MyApp5Service/Client"/>
        </baseAddresses>
      </host>
    </service>
    <service behaviorConfiguration="MyApp.ServiceImplementation.HL7Service_Behavior" name="MyApp.ServiceImplementation.HL7Service">
      <endpoint binding="basicHttpBinding" bindingConfiguration="BasicBindingHL7" contract="IHL7Service"/>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8004/MyApp5Service/Hl7"/>
        </baseAddresses>
      </host>
    </service>
  </services>
  <bindings>
    <netTcpBinding>
      <binding name="netTcpCertificate" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="infinite" sendTimeout="01:00:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="1000" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="200" maxReceivedMessageSize="2147483647">
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
        <reliableSession ordered="true" inactivityTimeout="infinite" enabled="false"/>
        <security mode="TransportWithMessageCredential">
          <transport clientCredentialType="Certificate"/>
          <message clientCredentialType="UserName"/>
        </security>
      </binding>
      <binding name="netTcpWindowMessageSecurity" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="infinite" sendTimeout="01:00:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="1000" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="200" maxReceivedMessageSize="2147483647">
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
        <reliableSession ordered="true" inactivityTimeout="infinite" enabled="false"/>
        <security mode="Message">
          <message clientCredentialType="Windows"/>
        </security>
      </binding>
      <!---->
      <binding name="netTcpRegular" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="infinite" sendTimeout="01:00:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="1000" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="200" maxReceivedMessageSize="2147483647">
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
        <reliableSession ordered="true" inactivityTimeout="infinite" enabled="false"/>
        <security mode="None">
          <transport clientCredentialType="None"/>
        </security>
      </binding>
    </netTcpBinding>
    <customBinding>
      <binding name="UsernamePasswordOverHttp">
        <textMessageEncoding messageVersion="Soap11"/>
        <security authenticationMode="UserNameOverTransport" messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" allowInsecureTransport="true"/>
        <httpsTransport/>
      </binding>
    </customBinding>
    <basicHttpBinding>
      <binding name="BasicMyAppIntegration" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="infinite" sendTimeout="01:00:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
        <security mode="None"/>
      </binding>
      <binding name="BasicBindingHL7" allowCookies="true" closeTimeout="04:00:00" openTimeout="04:00:00" receiveTimeout="04:00:00" sendTimeout="04:00:00" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">

        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
        <security mode="None">
          <transport clientCredentialType="None"/>
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>
</system.serviceModel>

1 个答案:

答案 0 :(得分:2)

在客户端看起来像一个简单的配置(单独发送); 使用的一个有趣的事情(在客户端配置中完全使用)是protoEndpointBehavior中定义的<endpointBehaviors>

<endpoint
  address="...(omitted).../Proto"
  behaviorConfiguration="BasicBehavior"
  ...(omitted)...
  name="SelfHostProto_RegularLogin"/>

如果我们将此BasicBehavior更改为protoEndpointBehavior,那么一切正常。邮件已正确发送和接收。