WCF 服务通过 https 返回 404,但不通过 http 返回 404
我正在将现有服务从 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>
我已经使用 basicHttpBinding
和 wsHttpBinding
进行了尝试,得到了相同的结果:
- 我可以从我的使用
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 with404: 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
检查 web.config 中的服务元素名称是否与实现合约的类的完全限定名称相匹配。
Check that your service element name in the web.config matches the fully qualified named of the class that implements your contract.
在 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.
HTTP 和 HTTPS 由不同的虚拟主机提供服务。您确定您的服务已正确安装在两者中吗?
HTTP and HTTPS are served from different virtual hosts. Are you sure your service is correctly installed in both?
感谢 Johann Blais 的回答,我发现您需要包含定义服务契约的类的完全限定名称。
例如,如果您的服务是
web.config 中相应的服务定义将是
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
The corresponding service definition in your web.config would be