【发布时间】:2015-01-05 15:18:22
【问题描述】:
我尝试了几种在网上发布的解决方案,但似乎都没有效果。
我对网络服务方法的响应是:
404:找不到文件或目录。
当我访问 AddressService.svc 文件的 http 版本时,我得到一个服务描述。当我访问该方法 (AddressService.svc/ValidateAddress) 时,我得到“不允许使用 GET 方法”,这是预期的,因为它只是一个 POST 方法。当我尝试 AddressService.svc 页面的 https 版本时,我还获得了服务描述。但是,当我尝试访问方法 (AddressService.svc/ValidateAddress) 时,我得到 404/not found 结果。
这是我目前在 web.config 中的内容:
绑定:
<bindings>
<basicHttpBinding>
<binding name="WebServiceSoap">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
服务:
<service name="DefiningVoiceWeb.AddressService" behaviorConfiguration="serviceBehavior">
<endpoint address="" binding="webHttpBinding" contract="DefiningVoiceWeb.IAddressService" behaviorConfiguration="web" />
<host>
<baseAddresses>
<add baseAddress="https://www.definingvoice.com/AdminOnly/AddressService.svc" />
</baseAddresses>
</host>
</service>
服务行为:
<serviceBehaviors>
<behavior name="serviceBehavior">
<!-- 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="true" />
</behavior>
</serviceBehaviors>
我还为 CORS 添加了这个:
<httpProtocol>
<customHeaders>
<clear />
<add name="X-Powered-By" value="ASP.NET" />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET, POST" />
</customHeaders>
</httpProtocol>
这是我的 IAddressService 声明:
[ServiceContract]
public interface IAddressService
{
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "/ValidateAddress",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
Address ValidateAddress(Address address);
}
还有AddressService.svc:
<%@ ServiceHost Language="C#" Debug="true" Service="DefiningVoiceWeb.AddressService" CodeBehind="AddressService.svc.cs" %>
我已经尝试了这些页面中的解决方案,但它们似乎都不适合我:
- How to convert wcf http web service to https
- SVC WebService works over HTTP, fails over HTTPS
- WCF Bindings Needed For HTTPS
如果我可能做错了什么,我很乐意尝试上述解决方案之一。如果我需要提供更多详细信息,请告诉我。
提前致谢。
阅读@pepo 提供的链接后,我发现了问题。以下是我使用最终工作配置编辑的部分:
服务:
<service name="DefiningVoiceWeb.AddressService" behaviorConfiguration="serviceBehavior">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpTransportSecurity" contract="DefiningVoiceWeb.IAddressService" behaviorConfiguration="webHttpBehavior" />
<host>
<baseAddresses>
<add baseAddress="https://www.definingvoice.com/AdminOnly/" />
</baseAddresses>
</host>
</service>
绑定:
<bindings>
<webHttpBinding>
<binding name="webHttpTransportSecurity">
<security mode="Transport">
</security>
</binding>
</webHttpBinding>
</bindings>
【问题讨论】:
-
您查看过事件日志吗?当您从 localhost 访问服务元数据时会发生什么?应该有更多关于激活服务缺少什么的信息。
-
不幸的是,我无法访问我托管该网站的事件日志。我将尝试在本地主机上的 IIS Express 中的 https 下运行该站点。我没想过要试试。我现在就试试……
-
好的,我取得了一些进展。在 localhost 上运行后,我发现 web.config 存在一些问题。我从 http 配置恢复到工作配置,然后添加了一些装饰,例如 mode="Transport" 和上面示例中的其他装饰。现在,当我转到与 http 版本类似的 https//...AddressService.svc 时,我得到了该服务的描述,但是当我尝试访问 AddressService.svc/ValidateAddress 方法时,响应不同(请参阅上面的更新)。有什么想法吗?
标签: web-services wcf https