C# 在asp.net中创建需要调用证书的HTTPS安全soap web服务
我正在尝试创建一个soap web服务,该服务将有一个web方法,该方法以名称作为输入,并通过HTTPS返回“hello”+名称,并且需要添加一些证书才能调用 我在IIS中创建了一个自签名证书,并添加了带有证书的HTTPS绑定。我已经在默认网站下添加了我的应用程序,并在其上启用了SSL 在VisualStudio中,我创建了WCF服务应用程序,并在其上启用了SSL。添加了类中仅包含一个方法的asmx文件。这是代码C# 在asp.net中创建需要调用证书的HTTPS安全soap web服务,c#,ssl,iis,soap,C#,Ssl,Iis,Soap,我正在尝试创建一个soap web服务,该服务将有一个web方法,该方法以名称作为输入,并通过HTTPS返回“hello”+名称,并且需要添加一些证书才能调用 我在IIS中创建了一个自签名证书,并添加了带有证书的HTTPS绑定。我已经在默认网站下添加了我的应用程序,并在其上启用了SSL 在VisualStudio中,我创建了WCF服务应用程序,并在其上启用了SSL。添加了类中仅包含一个方法的asmx文件。这是代码 using System; using System.Collections.Ge
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上工作,我们应该像您一样定义一个具有传输安全性的服务端点,以及服务契约、服务实现。此外,IIS站点绑定中的Https绑定是在Https上工作所必需的。
IService.cs
namespace POCSoap
{
[ServiceContract]
public interface IService1
{
string HelloWorld(string name);
}}
public class Service1 : IService1
{
public string HelloWorld(string name)
{
return "Hello " + name;
}
Service1.cs
namespace POCSoap
{
[ServiceContract]
public interface IService1
{
string HelloWorld(string name);
}}
public class Service1 : IService1
{
public string HelloWorld(string name)
{
return "Hello " + name;
}
但是,调用由客户端代理完成,而不是直接发送HTTP请求。至于ASMX服务,我们也需要使用客户端代理来调用它。因此,我想知道,当您已经在IIS中添加了https绑定时,为什么https调用无法工作。
要在WCF中创建RESTAPI,它可以通过简单的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服务。如果有什么我可以帮忙的,请随时告诉我。WCF服务是一种web服务,而不是XML web服务(ASMX)。它们是不同的web服务规范。
为了使WCF服务在HTTPS上工作,我们应该像您一样定义一个具有传输安全性的服务端点,以及服务契约、服务实现。此外,IIS站点绑定中的Https绑定是在Https上工作所必需的。
IService.cs
namespace POCSoap
{
[ServiceContract]
public interface IService1
{
string HelloWorld(string name);
}}
public class Service1 : IService1
{
public string HelloWorld(string name)
{
return "Hello " + name;
}
Service1.cs
namespace POCSoap
{
[ServiceContract]
public interface IService1
{
string HelloWorld(string name);
}}
public class Service1 : IService1
{
public string HelloWorld(string name)
{
return "Hello " + name;
}
但是,调用由客户端代理完成,而不是直接发送HTTP请求。至于ASMX服务,我们也需要使用客户端代理来调用它。因此,我想知道,当您已经在IIS中添加了https绑定时,为什么https调用无法工作。
要在WCF中创建RESTAPI,它可以通过简单的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服务。如果有什么我可以帮忙的,请随时告诉我。定义“不工作”。添加您收到的任何错误消息。@Gusman错误:阅读ECONNRESETdefine“不工作”。添加您收到的任何错误消息。@Gusman错误:read ECONNRESET