HTTP & HTTP WCF Services - PullRequest
       42

HTTP & HTTP WCF Services

3 голосов
/ 22 июня 2011

Могу ли я иметь проект службы WCF, имеющий привязки HTTP (базовая привязка http) и HTTPS (базовая привязка http)?Например, у меня будет:

https://localhost:44303/ServiceA.svc http://localhost:12345/ServiceB.svc

Будет ли какая-то польза от их размещения в отдельных сервисных проектах (и на отдельных сайтах при развертывании приложения)?

Ответы [ 2 ]

2 голосов
/ 22 июня 2011

Если у вас уже есть HTTP-привязка, вам не нужно менять код, чтобы добавить HTTPS-привязку. Это большое преимущество WCF. Вместо добавления отдельного сайта вы просто добавляете новую конечную точку в файл конфигурации.

Ниже приведен пример конфигурации с HTTP и HTTPS.
Вы можете видеть, что есть две именованные привязки: notSecureBinding и secureBinding, которые соответствуют HTTP и HTTPS.

  <bindings>
    <basicHttpBinding>
      <binding name="notSecureBinding"
               maxBufferSize="2147483647"
               maxReceivedMessageSize="2147483647">
        <security mode="None"/>
      </binding>
      <binding name="secureBinding"
               maxBufferSize="2147483647"
               maxReceivedMessageSize="2147483647">
        <security mode="Transport">
          <transport clientCredentialType="None"/>
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>
  <behaviors>
    <serviceBehaviors>
      <behavior name="StandardServiceBehavior">
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
        <serviceAuthorization principalPermissionMode="None"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service behaviorConfiguration="StandardServiceBehavior"
             name="ServiceName">
      <endpoint address=""
                binding="basicHttpBinding"
                bindingConfiguration="notSecureBinding"
                contract="Namespace.IService"/>
      <endpoint address=""
                binding="basicHttpBinding"
                bindingConfiguration="secureBinding"
                contract="Namespace.IService"/>
      <endpoint address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange"/>
    </service>
  </services>
0 голосов
/ 22 июня 2011

Я попытался это сделать, и когда я пытаюсь использовать мой безопасный сервис, я получаю следующую ошибку:

 The HTML document does not contain Web service discovery information. Metadata contains a reference that cannot be resolved: 'https://localhost:44304/ExternalOrderProcessing.svc'. There was no endpoint listening at https://localhost:44304/ExternalOrderProcessing.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. The remote server returned an error: (404) Not Found.If the service is defined in the current solution, try building the solution and adding the service reference again.

Когда я пытаюсь использовать мой незащищенный сервис, я получаю следующую ошибку:

 The HTML document does not contain Web service discovery information. Metadata contains a reference that cannot be resolved: 'http://localhost:5000/LegacyOrderProcessing.svc'. Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:5000/LegacyOrderProcessing.svc.  The client and service bindings may be mismatched. The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'.. If the service is defined in the current solution, try building the solution and adding the service reference again.

Я запускаю это в IIS Express.Я настроил проект, чтобы разрешить SSL.Моя конфигурация выглядит следующим образом:

<services>
  <service name="ExternalOrderProcessing" behaviorConfiguration="SecureBehavior">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBindingSecure" contract="IExternalOrderProcessing" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
  <service name="LegacyOrderProcessing" behaviorConfiguration="UnsecureBehavior">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding" contract="ILegacyOrderProcessing" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="SecureBehavior">
      <serviceMetadata httpsGetEnabled="true" httpsGetUrl=""/>
      <!-- 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="true"/>
      <serviceCredentials>
        <serviceCertificate findValue="localhost" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
        <clientCertificate>
          <authentication certificateValidationMode="None" />
        </clientCertificate>
      </serviceCredentials>
    </behavior>
    <behavior name="UnsecureBehavior">
      <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
      <!-- 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="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

<bindings>

  <basicHttpBinding>
    <!-- Used by external order processing service -->
    <binding name="BasicHttpBindingSecure"
            hostNameComparisonMode="StrongWildcard"
            maxBufferSize="2147483647"
            maxReceivedMessageSize="2147483647"
            receiveTimeout="00:05:00"
            sendTimeout="00:05:00"
            openTimeout="00:05:00"
            closeTimeout="00:05:00">
      <readerQuotas maxArrayLength="2147483647"/>
      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="Certificate" proxyCredentialType="None" realm="" />
        <message clientCredentialType="Certificate" algorithmSuite="Default"  />
      </security>
    </binding>
    <!-- Used to create binding to internal order processing service -->
    <binding name="BasicHttpBinding"
            hostNameComparisonMode="StrongWildcard"
            maxBufferSize="2147483647"
            maxReceivedMessageSize="2147483647"
            receiveTimeout="00:05:00"
            sendTimeout="00:05:00"
            openTimeout="00:05:00"
            closeTimeout="00:05:00">
      <readerQuotas maxArrayLength="2147483647"/>
      <security mode="None" />
    </binding>
  </basicHttpBinding>

</bindings>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

Если я размещу сервисы в двух отдельных проектах, это будет работать.Когда я это делаю, я пропускаю раздел служб в конфигурации и удаляю name = "BasicHttpBindingSecure" и name = "SecureBehavior".

...