首页 > 解决方案 > 将 WCF SOAP 和 WCF REST 服务托管为 Azure 应用服务

问题描述

我正在尝试将现有的 WCF 服务和 WCF REST 服务托管为 Azure 应用服务。我已经使用了 Visual Studio 中的 Publish 选项,就像这里的帖子一样

我能够浏览到 WCF SOAP 站点和 WCF REST 站点的托管 URL,但是当我为 WCF SOAP 站点添加服务引用并在其上调用方法时,出现以下错误

当我调用 REST 方法时,与 WCF 休息服务相同,我得到 404 now found 错误。

https://wcfservice.azurewebsites.net/WebService.svc上没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的。有关更多详细信息,请参阅 InnerException(如果存在)。远程服务器返回错误:(404) Not Found。

从失败的请求日志,即 w3svcxxxx 日志中,它显示请求https://WcfService:80/Webservice.svc 404 not found 状态。

对于 WCF Rest Service https://WcfService:80/RESTservice.svc/GetData 404 not found 状态。

为什么服务在内部调用https://WcfService:80,这是否需要配置才能设置。试图四处搜索,看看我是否能找到任何帮助,但找不到太多。

此外,我有另一个 WCF 站点,我已部署到应用服务,该站点使用 basicHttpBinding 进行设置,该站点运行良好,我能够使用它获取数据。

下面是网站上的 web.config 设置,我将 wsHttpBinging 用于 WCF SOAP 服务

 <system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="WebServiceOnline">
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <!-- 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="false" />
    </behavior>
  </serviceBehaviors>
   <endpointBehaviors>
    <behavior name="AjaxBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
  <service name="WcfService.WebServiceOnline" behaviorConfiguration="WebServiceOnline">
    <endpoint binding="wsHttpBinding" bindingName="wsSecurityByTransport" contract="WcfService.IWebServiceForOnline" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
  <service name="WcfService.RESTService" behaviorConfiguration="WebServiceOnline">
    <endpoint address="" binding="webHttpBinding" contract="WcfService.IRESTService" name="RunningBarbus.Services.RunningBarbusService" behaviorConfiguration="AjaxBehavior">
      <identity>
        <dns value="locahost" />
      </identity>
    </endpoint>
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="wsSecurityByTransport">
      <security mode="Transport">
        <transport clientCredentialType="None" />
        <message clientCredentialType="Certificate" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

标签: c#restazurewcfazure-web-app-service

解决方案


<services>   <service name="WcfService.WebServiceOnline" behaviorConfiguration="WebServiceOnline">
    <endpoint binding="wsHttpBinding" bindingName="wsSecurityByTransport" contract="WcfService.IWebServiceForOnline" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />   </service>   <service name="WcfService.RESTService" behaviorConfiguration="WebServiceOnline">
    <endpoint address="" binding="webHttpBinding" contract="WcfService.IRESTService" name="RunningBarbus.Services.RunningBarbusService" behaviorConfiguration="AjaxBehavior">
      <identity>
        <dns value="locahost" />
      </identity>
    </endpoint>
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />   </service> </services>

配置文件可能有问题。我们可以为 wshttpbinding 公开额外的服务端点。这是我的配置,它可以在 Azure 上正常运行。

<system.serviceModel>
    <services>
      <service behaviorConfiguration="mybehavior" name="WcfService1.Service1">
        <!--http, https are all configurated-->
        <endpoint address="" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="webbev" bindingConfiguration="mybinding"></endpoint>
        <endpoint address="" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="webbev" bindingConfiguration="com"></endpoint>
        <endpoint address="myservice" binding="wsHttpBinding" contract="WcfService1.IService1"></endpoint>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"></endpoint>
      </service>
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="mybinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" sendTimeout="00:10:00" receiveTimeout="00:10:00">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
          <security mode="Transport">
            <transport clientCredentialType="None"></transport>
          </security>
        </binding>
        <binding name="com">
          <security mode="None"></security>
        </binding>
      </webHttpBinding>
</bindings>

结果 在此处输入图像描述 如果有什么我可以帮忙的,请随时告诉我。


推荐阅读