我已尝试在网上发布了多个解决方案,但这些解决方案似乎都没有效果。
我对Web服务方法的回应是:
404:找不到文件或目录。
当我访问 AddressService.svc 文件的http版本时,我获得了服务描述。当我访问方法( AddressService.svc / ValidateAddress )时,我得到" GET方法不允许",这是预期的,因为它只是一个POST方法。当我尝试 AddressService.svc 页面的 https 版本时,我也会获得服务说明。但是,当我尝试访问该方法( AddressService.svc / ValidateAddress )时,我得到404 /未找到结果。
以下是我目前在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" %>
我已尝试过这些网页的解决方案,但这些解决方案似乎都不适用于我:
如果有可能我做错了,我很乐意尝试上述解决方案之一。如果我需要提供更多详细信息,请告诉我。
提前致谢。
在阅读@ 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>
答案 0 :(得分:1)
那么,为什么在使用weHttpBinding时编辑basicHttp
绑定配置?
This SO answer可能对您有所帮助(虽然我没有测试过)。有一篇很好的文章引用了解释如何使用webHttpBinding设置https。