WCF 服务通过 https 返回 404,但不通过 h​​ttp 返回 404

发布于 2024-09-26 02:01:51 字数 2668 浏览 0 评论 0原文

我正在将现有服务从 HTTP(开发/UAT)迁移到 HTTPS(生产),但在配置方面遇到了问题。这是我的 web.config 的 system.serviceModel 部分:

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
    <services>
      <service name="MyService">
        <endpoint name="MyEndpoint" address="" binding="wsHttpBinding"
            bindingConfiguration="secureBinding" contract="IMyService" />
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="secureBinding">
          <security mode="Transport"></security>
        </binding>
      </wsHttpBinding>
    </bindings>
</system.serviceModel>

我已经使用 basicHttpBindingwsHttpBinding 进行了尝试,得到了相同的结果:

  • 我可以从我的使用 http://server.domain.com/MyService.svc 的 SOAP 客户端
  • 我可以使用 https://server.domain.com/MyService.svc 从浏览器访问该服务code>
  • 我无法使用 https://server.domain.com/MyService.svc 从 SOAP 客户端调用该服务 - 调用始终出错,并显示 404:未找到

我的 https 站点使用公司域上的 CA 颁发的证书进行了认证,并且我已验证我已将该 CA 的证书安装在我所在系统的受信任的根证书颁发机构中我正在打电话。

相关的客户端代码:

Service service = new Service();
service.Url = "http://server.domain.com/MyService.svc";
//service.Url = "https://server.domain.com/MyService.svc";
service.WebMethodCall();

编辑

以下是 WSDL 的请求部分:

<wsdl:types/>
<wsdl:portType name="IMyService"/>
<wsdl:binding name="BasicHttpBinding_IMyService" type="tns:IMyService">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
</wsdl:binding>
<wsdl:service name="MyService">
    <wsdl:port name="BasicHttpBinding_IMyService" 
        binding="tns:BasicHttpBinding_IMyService">
        <soap:address location="http://server.domain.com/MyService.svc"/>
    </wsdl:port>
</wsdl:service>

编辑

更多信息:

当我将 serviceMetadata 元素更改为具有 httpGetEnabled="false"< /code> 和 httpsGetEnabled="true" .svc 页面显示以下链接:

https://boxname.domain.com/MyService.svc?wsdl

而不是预期的

https://server.domain.com/MyService.svc?wsdl

I'm migrating an existing service from HTTP (Dev/UAT) to HTTPS (Production), and I'm having trouble with the configuration. Here is the system.serviceModel section of my web.config:

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
    <services>
      <service name="MyService">
        <endpoint name="MyEndpoint" address="" binding="wsHttpBinding"
            bindingConfiguration="secureBinding" contract="IMyService" />
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="secureBinding">
          <security mode="Transport"></security>
        </binding>
      </wsHttpBinding>
    </bindings>
</system.serviceModel>

I've tried this using both basicHttpBinding and wsHttpBinding, with the same results:

  • I can call the service from my SOAP client using http://server.domain.com/MyService.svc
  • I can hit the service from a browser using https://server.domain.com/MyService.svc
  • I can't call the service from my SOAP client using https://server.domain.com/MyService.svc - the call always errors with 404: not found.

My https site is certified using a certificate that was issued by a CA on the corporate domain, and I've verified that I have that CA's certificate installed in Trusted Root Certification Authorities on the system from which I'm making the calls.

The relevant client code:

Service service = new Service();
service.Url = "http://server.domain.com/MyService.svc";
//service.Url = "https://server.domain.com/MyService.svc";
service.WebMethodCall();

EDIT

Here are the requested portions of the WSDL:

<wsdl:types/>
<wsdl:portType name="IMyService"/>
<wsdl:binding name="BasicHttpBinding_IMyService" type="tns:IMyService">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
</wsdl:binding>
<wsdl:service name="MyService">
    <wsdl:port name="BasicHttpBinding_IMyService" 
        binding="tns:BasicHttpBinding_IMyService">
        <soap:address location="http://server.domain.com/MyService.svc"/>
    </wsdl:port>
</wsdl:service>

EDIT

More information:

When I change the serviceMetadata element to have httpGetEnabled="false" and httpsGetEnabled="true" the .svc page shows me the following link:

https://boxname.domain.com/MyService.svc?wsdl

rather than the expected

https://server.domain.com/MyService.svc?wsdl

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

鹿港小镇 2024-10-03 02:01:51

检查 web.config 中的服务元素名称是否与实现合约的类的完全限定名称相匹配。

<services>
  <service name="MyNamespace.MyService">
    <endpoint name="MyEndpoint" address="" binding="wsHttpBinding" ...

Check that your service element name in the web.config matches the fully qualified named of the class that implements your contract.

<services>
  <service name="MyNamespace.MyService">
    <endpoint name="MyEndpoint" address="" binding="wsHttpBinding" ...
蒗幽 2024-10-03 02:01:51

在 WSDL 中,您会看到您的服务不公开 HTTPS 上的端口,而仅公开 HTTP 上的端口。此外,您还可以看到您的服务使用BasicHttpBinding(请参阅端口名称和绑定名称)。这意味着您的服务配置根本没有被使用。检查服务元素中的名称是否与 .svc 标记中的名称相同。它必须被定义,包括命名空间。

In your WSDL you see that your service does not expose port on HTTPS but only on HTTP. Moreover you can also see that your service uses BasicHttpBinding (see port name and binding name). That means that your service configuration is not used at all. Check that name in the service element is same as name in your .svc markup. It has to be defined including namespaces.

玩世 2024-10-03 02:01:51

HTTP 和 HTTPS 由不同的虚拟主机提供服务。您确定您的服务已正确安装在两者中吗?

HTTP and HTTPS are served from different virtual hosts. Are you sure your service is correctly installed in both?

阪姬 2024-10-03 02:01:51

感谢 Johann Blais 的回答,我发现您需要包含定义服务契约的类的完全限定名称。

例如,如果您的服务是

namespace MyCompany.WcfService
{

    [ServiceContract(Namespace="http://xsd.mycompany.com/mcy/1_0_0")]
    public interface IService
    {
        [OperationContract(IsOneWay = false)]
        void DoStuff()
    }

    public class Service : IService
    {
        void DoStuff()
        {
        }
    }
}

web.config 中相应的服务定义将是

<system.serviceModel>
    <services>
        <service name="MyCompany.WcfService.IService">
            <endpoint address="" binding="basicHttpBinding" contract="MyCompany.WcfService.IService" />
        </service>
    </services>
    ...
</system.serviceModel>

Thanks to Johann Blais for the answer, I've found out that you would need to include the fully qualified name for the class that defines the service contract.

For example if your service is

namespace MyCompany.WcfService
{

    [ServiceContract(Namespace="http://xsd.mycompany.com/mcy/1_0_0")]
    public interface IService
    {
        [OperationContract(IsOneWay = false)]
        void DoStuff()
    }

    public class Service : IService
    {
        void DoStuff()
        {
        }
    }
}

The corresponding service definition in your web.config would be

<system.serviceModel>
    <services>
        <service name="MyCompany.WcfService.IService">
            <endpoint address="" binding="basicHttpBinding" contract="MyCompany.WcfService.IService" />
        </service>
    </services>
    ...
</system.serviceModel>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文