在Azure Web角色上启用HTTPS WCF Web服务的配置

在Azure Web角色上启用HTTPS WCF Web服务的配置,wcf,azure,Wcf,Azure,我已经搜索了几篇与此领域相关的文章(例如),但似乎没有一篇能够解决这个相当直接的场景问题:在Azure Web角色上配置启用SSL(例如https)的WCF Web服务应该使用什么绑定配置:在Web角色的ServiceDefinition.csdef中,Web服务的Web.config和客户端的app.config 我已在Azure门户和Web角色的ServiceConfiguration.csfg(https://MyApp.cloudapp.net)中为该服务配置了SSL证书,该证书似乎工作

我已经搜索了几篇与此领域相关的文章(例如),但似乎没有一篇能够解决这个相当直接的场景问题:在Azure Web角色上配置启用SSL(例如https)的WCF Web服务应该使用什么绑定配置:在Web角色的ServiceDefinition.csdef中,Web服务的Web.config和客户端的app.config

我已在Azure门户和Web角色的ServiceConfiguration.csfg(https://MyApp.cloudapp.net)中为该服务配置了SSL证书,该证书似乎工作正常

当我浏览到服务https://myapp.cloudapp.net/WCFService.svc?wsdl时,元数据显示正确。我可以从客户端向服务添加服务引用,但是当我调用它时,我得到了一个异常:“https://myapp.cloudapp.net/WCFService.svc上没有端点侦听可以接受消息。这通常是由于地址或SOAP操作不正确造成的。有关详细信息,请参阅InnerException(如果存在)。”内部异常:“远程服务器返回错误:(404)未找到”

相应的配置文件如下所示: ServiceDefinition.csdef:

<WebRole name="WCFServiceWebRole" vmsize="Small">
    <Sites>
      <Site name="Web">
        <Bindings>
          <Binding name="HttpIn" endpointName="HttpIn" />
          <Binding name="HttpsIn" endpointName="HttpsIn" />
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="HttpIn" protocol="http" port="8080" />
      <InputEndpoint name="HttpsIn" protocol="https" port="443" certificate="MySSLCert" />
    </Endpoints>
    <Certificates>
      <Certificate name="MySSLCert" storeLocation="LocalMachine" storeName="My" />
    </Certificates>
  </WebRole>
<WebRole name="WCFServiceWebRole" vmsize="Small">
    <Sites>
      <Site name="Web">
        <Bindings>
          <Binding name="HttpIn" endpointName="HttpIn" />
          <Binding name="HttpsIn" endpointName="HttpsIn" />
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="HttpIn" protocol="http" port="8080" />
      <InputEndpoint name="HttpsIn" protocol="https" port="443" certificate="MySSLCert" />
    </Endpoints>
    <Certificates>
      <Certificate name="MySSLCert" storeLocation="LocalMachine" storeName="My" />
    </Certificates>
  </WebRole>

Web服务的Web.config:

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>              
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding" />
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>
<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>              
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding" />
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="" name="MyWebServiceNameSpace.MyWebService">
      <endpoint bindingConfiguration="BasicHttpBinding" address="" binding="basicHttpBinding"
    contract="MyWebServiceNameSpace.IMyWebService" />
      <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
     </service>
   </services>
  </system.serviceModel>

客户端的App.Config如下所示:

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IMyWebService" >
                 <security mode="Transport">
                    <transport clientCredentialType="None" />
                 </security>
             </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://myapp.cloudapp.net/MyWebService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyWebService"
                contract="MyWebServiceServiceReference.IMyWebService"
                name="BasicHttpBinding_IMyWebService" />
        </client>
    </system.serviceModel>
<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IMyWebService" >
                 <security mode="Transport">
                    <transport clientCredentialType="None" />
                 </security>
             </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://myapp.cloudapp.net/MyWebService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyWebService"
                contract="MyWebServiceServiceReference.IMyWebService"
                name="BasicHttpBinding_IMyWebService" />
        </client>
    </system.serviceModel>

当我使用SvcUtil为客户端生成绑定配置时,它会生成:

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IMyWebService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://myapp.cloudapp.net/MyWebService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyWebService"
                contract="MyWebServiceServiceReference.IMyWebService" name="BasicHttpBinding_IMyWebService" />
        </client>
    </system.serviceModel>

当我调用web服务时,会出现异常:“提供的URI方案‘https’无效;应为‘http’”,因此这似乎也不是正确的配置

我确信这只是在上面的三个文件中获得正确配置的问题,但我似乎在任何地方都找不到正确的组合,因此如果有人能说出它们应该是什么,我将非常感激。
Conor。

一个Azure开发人员帮助我找到了答案,问题是Web服务的Web.config文件中遗漏了服务节点。以下是此场景所需的完整配置文件集,以防它帮助其他试图实现相同结果的人(在Azure Web角色上实现的SSL/HTTPS WCF Web服务:

ServiceDefinition.csdef:

<WebRole name="WCFServiceWebRole" vmsize="Small">
    <Sites>
      <Site name="Web">
        <Bindings>
          <Binding name="HttpIn" endpointName="HttpIn" />
          <Binding name="HttpsIn" endpointName="HttpsIn" />
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="HttpIn" protocol="http" port="8080" />
      <InputEndpoint name="HttpsIn" protocol="https" port="443" certificate="MySSLCert" />
    </Endpoints>
    <Certificates>
      <Certificate name="MySSLCert" storeLocation="LocalMachine" storeName="My" />
    </Certificates>
  </WebRole>
<WebRole name="WCFServiceWebRole" vmsize="Small">
    <Sites>
      <Site name="Web">
        <Bindings>
          <Binding name="HttpIn" endpointName="HttpIn" />
          <Binding name="HttpsIn" endpointName="HttpsIn" />
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="HttpIn" protocol="http" port="8080" />
      <InputEndpoint name="HttpsIn" protocol="https" port="443" certificate="MySSLCert" />
    </Endpoints>
    <Certificates>
      <Certificate name="MySSLCert" storeLocation="LocalMachine" storeName="My" />
    </Certificates>
  </WebRole>

Web服务的Web.config:

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>              
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding" />
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>
<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>              
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding" />
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="" name="MyWebServiceNameSpace.MyWebService">
      <endpoint bindingConfiguration="BasicHttpBinding" address="" binding="basicHttpBinding"
    contract="MyWebServiceNameSpace.IMyWebService" />
      <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
     </service>
   </services>
  </system.serviceModel>

客户端的App.Config如下所示:

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IMyWebService" >
                 <security mode="Transport">
                    <transport clientCredentialType="None" />
                 </security>
             </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://myapp.cloudapp.net/MyWebService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyWebService"
                contract="MyWebServiceServiceReference.IMyWebService"
                name="BasicHttpBinding_IMyWebService" />
        </client>
    </system.serviceModel>
<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IMyWebService" >
                 <security mode="Transport">
                    <transport clientCredentialType="None" />
                 </security>
             </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://myapp.cloudapp.net/MyWebService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyWebService"
                contract="MyWebServiceServiceReference.IMyWebService"
                name="BasicHttpBinding_IMyWebService" />
        </client>
    </system.serviceModel>

谢谢,对我也有用!
我在删除服务定义中的证书部分时做了一些更改

<WebRole name="WCFServiceBizagiCloud" vmsize="Standard_D1_v2">
    <Sites>
      <Site name="Web">
        <Bindings>
          <!--<Binding name="Endpoint1" endpointName="Endpoint1" />-->
          <Binding name="HttpIn" endpointName="HttpIn" />
          <Binding name="HttpsIn" endpointName="HttpsIn" />
        </Bindings>
      </Site>
    </Sites>
    <ConfigurationSettings>
      <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" />
    </ConfigurationSettings>
    <Endpoints>
      <!--<InputEndpoint name="Endpoint1" protocol="http" port="80" />-->
      <InputEndpoint name="HttpIn" protocol="http" port="8080" />
      <InputEndpoint name="HttpsIn" protocol="https" port="443"  />
    </Endpoints>
    <!--<Certificates>
      <Certificate name="MySSLCert" storeLocation="LocalMachine" storeName="My" />
    </Certificates>-->
  </WebRole>


对我来说效果很好!谢谢!Web服务的Web.config中有一个错误。您可以打开和关闭绑定节点:
,但实际上这应该只是一个普通的标记,因为稍后将使用
关闭它。