首页 > 解决方案 > 无法添加托管在 azure 中的 WCF 服务

问题描述

我在服务器上托管了一项 WCF 服务

http://firstdomain.com/WebStorePrice/PickStorePrice.svc

它在我的机器上运行。现在我将它作为 azure 服务托管到新服务器,当尝试添加服务引用时出现错误

下载“ https://service.azurewebsites.net/PickStorePrice.svc/$metadata ”时出错。请求失败,HTTP 状态为 404:未找到。元数据包含无法解析的引用:“ https://service.azurewebsites.net/PickStorePrice.svc ”。在https://service.azurewebsites.net/PickStorePrice.svc上没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的。有关更多详细信息,请参阅 InnerException(如果存在)。远程服务器返回错误:(404) Not Found。如果在当前解决方案中定义了服务,请尝试构建解决方案并再次添加服务引用。wcf 服务的 webconfig 看起来像

      <system.serviceModel>
        <services>
          <service name="WebStorePrice.PickStorePrice" behaviorConfiguration="cstmServiceConfig">
            <endpoint address="" binding="basicHttpBinding" contract="WebStorePrice.IPickStorePrice"/>
          </service>
        </services>
        <bindings>
          <webHttpBinding>
            <binding name="secure">
              <security mode="Transport">
                <transport clientCredentialType="Basic"/>
              </security>
            </binding>
          </webHttpBinding>
        </bindings>
        <behaviors>
          <endpointBehaviors>
            <behavior name="cstmendpointConfig">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="cstmServiceConfigOnline">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
            <behavior name="cstmServiceConfig">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
      </system.serviceModel>

标签: web-serviceswcf

解决方案


从服务配置来看,我们的服务不支持Https协议,因为Azuredocker(Paas)server 默认通过 Https 进行通信。因此,我们应该配置一个额外的服务端点来支持 WCF over https。
对于 Soap 风格的 Web 服务,请参考以下配置。

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
      <add binding="basicHttpBinding" scheme="http"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

关于 WCF Restful 风格的服务。

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior>
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <webHttpBinding>
        <binding name="mybinding">
          <security mode="Transport">
            <transport clientCredentialType="None"></transport>
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <protocolMapping>
      <add binding="webHttpBinding" scheme="http"/>
      <add binding="webHttpBinding" scheme="https" bindingConfiguration="mybinding"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

如果问题仍然存在,请随时告诉我。


推荐阅读