WCF服务适用于HTTP,但不适用于HTTPS

时间:2019-06-19 17:17:24

标签: azure wcf iis azure-cloud-services

我已经开发并发布了托管在Azure云服务(经典)中的WCF服务。我已经安装了证书,并将云服务配置为使用证书。这是从CA购买的证书,而不是自签名证书。我最初怀疑证书有问题,但是正如Steffen在他的评论中指出的那样,情况似乎并非如此。我可以通过HTTP发送POST请求,并获得200响应。但是,如果我尝试通过HTTPS发送POST请求,则会收到404响应。这是两个请求之间的唯一区别。需要使用HTTPS。

我已经将IIS配置为发送本地和远程调用的详细错误消息,但是除了基本的404(找不到)之外,我仍然没有得到任何信息。

这是服务定义(.csdef)文件中的绑定和端点部分。

<Bindings>
    <Binding name="HttpsIn" endpointName="HttpsIn" />
    <Binding name="Endpoint1" endpointName="Endpoint1" />
</Bindings>

<Endpoints>
    <InputEndpoint name="HttpsIn" protocol="https" port="443" certificate="mycertificate" />
    <InputEndpoint name="Endpoint1" protocol="http" port="80" />  
</Endpoints>

这是web.config文件中的绑定部分:

    <bindings>
      <basicHttpBinding>
        <binding name="HttpsIn">
          <security mode="Transport"></security>
        </binding>
      </basicHttpBinding>
    </bindings>

这有效,返回200响应:

POST http://mydomain/myservice.svc HTTP/1.1
User-Agent: Fiddler
Host: mydomain
Content-Length: 600
Content-Type: text/xml; charset=utf-8
SOAPAction: "myclass/myaction"

<?xml version="1.0" etc, etc

失败,返回404响应:

POST https://mydomain/myservice.svc HTTP/1.1
User-Agent: Fiddler
Host: mydomain
Content-Length: 600
Content-Type: text/xml; charset=utf-8
SOAPAction: "myclass/myaction"

<?xml version="1.0" etc, etc

响应:

HTTP/1.1 404 Not Found
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET
Date: Thu, 20 Jun 2019 09:40:02 GMT
Content-Length: 0

我尝试了以下亚伯拉罕·奎安建议的更改。我的服务配置主要是由Abraham指示的,除了它没有aspNetCompatibilityEnabled属性或protocolMapping部分,因此我添加了这些配置。我的IIS绑定如Abraham所示,但使用的是特定IP地址而不是“ All Assigned”,因此我也进行了更改。经过这些更改,我得到了服务激活异常。错误消息指示aspNetCompatibilityEnabled属性存在问题,因此我再次将其撤消。现在,尝试远程浏览到站点时,我得到了503,服务不可用,但是登录到服务器后,我能够浏览到站点。看来IP地址可能有问题,因此我将IIS绑定更改为再次使用特定IP地址。我现在回到了开始的地方-该服务通过http工作,但尝试通过https调用时得到了404。

总而言之,我可以使用HTTP或HTTPS在浏览器(mydomain / myservice.svc?wsdl)中显示WSDL。我可以使用HTTP或HTTPS使用GET调用SOAP操作方法。当然,这不会返回所需的结果,因为该方法需要使用POST进行调用,但是它会返回“您已创建服务”页面的内容。 404仅在HTTPS和POST结合使用时发生。

HTTP + GET = 200, 
HTTPS + GET = 200, 
HTTP + POST = 200, 
HTTPS + POST = 404.

1 个答案:

答案 0 :(得分:0)

伙计,似乎通过https发布服务的过程出现了问题。
请使用以下配置启用https和http。
服务器配置。

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

然后,在IIS网站绑定模块中添加http绑定和https绑定。
IIS网站绑定 enter image description here
必须注意的一件事是该服务不是Restful的,它只是在SOAP消息中起作用。我们可以使用客户端代理来调用它。如下图所示。
客户端。

ServiceReference1.Service1Client client = new ServiceReference1.Service1Client("BasicHttpsBinding_IService1");
            try
            {
                var result = client.GetData(34);
                Console.WriteLine(result);
            }
            catch (Exception)
            {
                throw;
            }

客户端配置。

    <system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IService1" />
            <binding name="BasicHttpsBinding_IService1">
                <security mode="Transport" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://vabqia969vm:11000/Service1.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
            name="BasicHttpBinding_IService1" />
        <endpoint address="https://vabqia969vm:11001/Service1.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpsBinding_IService1" contract="ServiceReference1.IService1"
            name="BasicHttpsBinding_IService1" />
    </client>
</system.serviceModel>

上述客户端代理类(service1client)是通过在我的项目中添加服务引用而生成的。
随时让我知道是否有什么可以帮助您的。

相关问题