首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HTTP和HTTP WCF服务

HTTP和HTTP WCF服务
EN

Stack Overflow用户
提问于 2011-06-22 10:25:03
回答 2查看 638关注 0票数 3

我是否可以拥有同时具有HTTP (基本http绑定)和HTTPS (基本http绑定)绑定的WCF服务项目?例如,我会:

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

将它们放在单独的服务项目中(当我们部署应用程序时,将它们放入单独的站点)会有什么好处吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-06-22 10:30:34

如果你已经有了HTTP绑定,你不需要修改代码来添加HTTPS绑定。这是WCF的一个很大的优势。您只需将新端点添加到配置文件中,而不是添加单独的站点。

下面是同时使用HTTP和HTTPS的配置示例。

您可以看到有两个命名绑定: notSecureBinding和secureBinding,它们对应于HTTP和HTTPS。

代码语言:javascript
复制
  <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>
票数 2
EN

Stack Overflow用户

发布于 2011-06-22 23:38:40

我尝试这样做,当我尝试使用我的安全服务时,我得到了以下错误:

代码语言:javascript
复制
 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.

当我尝试使用不安全的服务时,我得到以下错误:

代码语言:javascript
复制
 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。我的配置如下:

代码语言:javascript
复制
<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”。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6434233

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档