WCF Web服务移至Azure VM

时间:2019-03-07 14:00:25

标签: azure wcf iis

我有一个旧的WCF Web服务已被移到Azure VM。

我可以在Azure中轻松访问: https://wcf/service.svc, 但是当我尝试发布到: https://wcf/service.svc/json/DoAction 它返回一个空响应,当我在浏览器中打开它时,出现404错误。

在Azure之外,一切正常,我有什么想法可以使其正常工作?我希望它可以在VM中运行,因为还有其他项目已移动并且可以正常工作。

这是web.config文件中与“ / json /”部分有关的部分:

<system.serviceModel>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  <services>
    <service name="Service123" behaviorConfiguration="ChallengeBehavior">
      <endpoint address="" binding="wsHttpBinding" bindingConfiguration="ChallengeMessageEncoding" contract="IService123" behaviorConfiguration="SoapServiceBehavior" />
      <endpoint address="/json" binding="webHttpBinding" bindingConfiguration="RestServiceMessageEncoding" contract="IService123" behaviorConfiguration="RestServiceBehavior" />
    </service>
  </services>
  <behaviors>
    <endpointBehaviors>
      <behavior name="RestServiceBehavior">
        <webHttp defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" />
      </behavior>
      <behavior name="SoapServiceBehavior">
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <bindings>
    <webHttpBinding>
      <binding name="RestServiceMessageEncoding">
        <security mode="None">
        </security>
      </binding>
    </webHttpBinding>
    <wsHttpBinding>
      <binding name="ChallengeMessageEncoding">
        <security mode="None">
          <transport clientCredentialType="None" proxyCredentialType="None" />
          <message clientCredentialType="None" establishSecurityContext="false" negotiateServiceCredential="false" />
        </security>
      </binding>
    </wsHttpBinding>
  </bindings>
</system.serviceModel>

2 个答案:

答案 0 :(得分:1)

在我看来,代码片段没有问题。 Azure VM中安装了哪个版本的IIS?您是否已启用IIS中WCF支持的功能。 enter image description here
我怀疑在VM上发布的WCF服务无法正常运行。尝试发布默认的WCF服务应用程序项目并浏览自我介绍页面。
此外,对于特定端口,您需要在防火墙上启用出站/入站权限。

  

VM >>设置>>网络

如果有任何需要帮助的地方,请随时与我联系。

答案 1 :(得分:0)

@亚伯拉罕,谢谢您的回答。

我终于使它起作用了,不确定是哪一部分有用,但是我引入了一些变化:

a)安装了其他WCF功能(如上所述),因为仅安装了2个

b)在Web配置中添加了一些额外的位(允许运行名称为/Foo.svc/Save的带点的URL)

<handlers>
  <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
  <remove name="OPTIONSVerbHandler" />
  <remove name="TRACEVerbHandler" />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
  <clear />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="/*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>

c)另一个支持点的配置:

<modules runAllManagedModulesForAllRequests="true" />

d)扩展端点支持HTTPS,因为上述内容开始适用于HTTP:

  <service name="PrivateService" behaviorConfiguration="PrivateBehavior">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="PrivateBehavior" contract="IPrivateService" behaviorConfiguration="SoapBehavior" />
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="PrivateBehaviorSecure" contract="IPrivateService" behaviorConfiguration="SoapBehavior" />
    <endpoint address="/json" binding="webHttpBinding" bindingConfiguration="RestSecure" contract="IPrivateServices" behaviorConfiguration="RestBehavior" />
    <endpoint address="/json" binding="webHttpBinding" bindingConfiguration="Rest" contract="IPrivateService" behaviorConfiguration="RestBehavior" />
  </service>
  ...
  <webHttpBinding>
    <binding name="Rest">
      <security mode="None">
      </security>
    </binding>
    <binding name="RestSecure">
      <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None" />
      </security>
    </binding>
  </webHttpBinding>