在需要调用证书的 asp.net 中创建 HTTPS 安全 SOAP Web 服务



我正在尝试创建一个肥皂网络服务,该服务将有一个以名称为输入的Web方法,并将通过HTTPS返回"hello "+name,并且需要添加一些证书才能被调用。

我在 IIS 中创建了一个自签名证书,并添加了带有证书的 HTTPS 绑定。我已经在默认网站下添加了我的应用程序,并在其上启用了SSL。

在视觉工作室中,我创建了WCF服务应用程序,并在其上启用了SSL。添加了类中仅包含一个方法的 asmx 文件。这是代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace POCSoap
{
[WebService(Namespace = "https://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld(string name)
{
return "Hello "+name;
}
}
}

我也在 web.config 中添加了绑定和服务声明。

<services>
<service name="POCSoap.Service1">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="secureHttpBinding"
contract="POCSoap.IService1"/>
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="secureHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>

尽管如此,通过http调用是有效的,通过https调用是不工作的。这里缺少什么。

WCF 服务是 XML Web 服务 (ASMX( 以外的 Web 服务。它们是不同的 Web 服务规范。
为了使 WCF 服务通过 HTTPS 工作,我们应该像您一样定义具有传输安全性的服务终结点以及服务协定、服务实现。此外,通过 HTTPS 工作需要 IIS 站点绑定中的 Https 绑定。
是服务.cs

namespace POCSoap
{
[ServiceContract]
public interface IService1
{
string HelloWorld(string name);
}}

服务1.cs

public class Service1 : IService1
{
public string HelloWorld(string name)
{
return "Hello " + name;
}

但是,调用由客户端代理完成,而不是直接发送 HTTP 请求。
https://learn.microsoft.com/en-us/dotnet/framework/wcf/accessing-services-using-a-wcf-client#add-service-reference-in-visual-studio
至于ASMX服务,我们也需要使用客户端代理调用它。 因此,我想知道为什么当您已经在 IIS 中添加了 https 绑定时,通过 https 的调用不起作用。
要在 WCF 中创建 Rest API,它可以直接使用简单的 Http 请求(http 动词,请求正文(调用,我们需要更改创建 WCF 服务的方式。

<system.serviceModel>
<services>
<service name="WcfService3.Service1">
<endpoint address="" binding="webHttpBinding" contract="WcfService3.IService1" behaviorConfiguration="rest"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="rest">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>

最后,要求调用证书是什么意思? 您想使用证书对客户端进行身份验证,对吗?这取决于您使用的 Web 服务(WCF 服务或 Xml Web 服务(。
如果有什么我可以帮忙的,请随时告诉我。

最新更新