.net - 如何在 .NET Framework 中使用 HTTPS SOAP Webservice?
问题描述
我正在开发一个集成 .NET Framework WebJob,它包括序列化一个 . xml
并将文件信息发送到客户端提供的 SOAP WebService。我有一个类,其工作方式类似于实现的代理System.Web.Services.Protocols.SoapHttpClientProtocol
,它允许我实际使用 WebService。
由于客户端 web 服务在 https 中,如果我在本地安装证书,我可以调试我的服务并且它工作正常。但是当我将它部署到天蓝色时,它显然在下面给了我这个错误。
System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
[02/09/2021 11:12:16 > 559726: INFO] at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
我的问题是它是否有某种我缺少的实现?有没有办法解决实际需要在本地安装证书?我怎样才能在云中做到这一点?
下面是我的代理代码:
namespace nav {
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.8.3928.0")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="Logitude_Invoice_Integration_Binding", Namespace="urn:microsoft-dynamics-schemas/codeunit/Logitude_Invoice_Integration")]
public partial class Logitude_Invoice_Integration : System.Web.Services.Protocols.SoapHttpClientProtocol {
private System.Threading.SendOrPostCallback ImportOrderOperationCompleted;
/// <remarks/>
public Logitude_Invoice_Integration() {
this.Url = ""; // populated by the clients soap Webservice URL
}
/// <remarks/>
public event ImportOrderCompletedEventHandler ImportOrderCompleted;
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("urn:microsoft-dynamics-schemas/codeunit/Logitude_Invoice_Integration:ImportOrder", RequestNamespace="urn:microsoft-dynamics-schemas/codeunit/Logitude_Invoice_Integration", ResponseElementName="ImportOrder_Result", ResponseNamespace="urn:microsoft-dynamics-schemas/codeunit/Logitude_Invoice_Integration", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public void ImportOrder(Logitude p_xmlARInvoices1050, ref string p_txtResponseText, ref string p_txtResponseErrorText, ref string p_codeCreatedDocNo) {
object[] results = this.Invoke("ImportOrder", new object[] {
p_xmlARInvoices1050,
p_txtResponseText,
p_txtResponseErrorText,
p_codeCreatedDocNo});
p_txtResponseText = ((string)(results[0]));
p_txtResponseErrorText = ((string)(results[1]));
p_codeCreatedDocNo = ((string)(results[2]));
}
/// <remarks/>
public System.IAsyncResult BeginImportOrder(Logitude p_xmlARInvoices1050, string p_txtResponseText, string p_txtResponseErrorText, string p_codeCreatedDocNo, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("ImportOrder", new object[] {
p_xmlARInvoices1050,
p_txtResponseText,
p_txtResponseErrorText,
p_codeCreatedDocNo}, callback, asyncState);
}
/// <remarks/>
public void EndImportOrder(System.IAsyncResult asyncResult, out string p_txtResponseText, out string p_txtResponseErrorText, out string p_codeCreatedDocNo) {
object[] results = this.EndInvoke(asyncResult);
p_txtResponseText = ((string)(results[0]));
p_txtResponseErrorText = ((string)(results[1]));
p_codeCreatedDocNo = ((string)(results[2]));
}
/// <remarks/>
public void ImportOrderAsync(Logitude p_xmlARInvoices1050, string p_txtResponseText, string p_txtResponseErrorText, string p_codeCreatedDocNo) {
this.ImportOrderAsync(p_xmlARInvoices1050, p_txtResponseText, p_txtResponseErrorText, p_codeCreatedDocNo, null);
}
/// <remarks/>
public void ImportOrderAsync(Logitude p_xmlARInvoices1050, string p_txtResponseText, string p_txtResponseErrorText, string p_codeCreatedDocNo, object userState) {
if ((this.ImportOrderOperationCompleted == null)) {
this.ImportOrderOperationCompleted = new System.Threading.SendOrPostCallback(this.OnImportOrderOperationCompleted);
}
this.InvokeAsync("ImportOrder", new object[] {
p_xmlARInvoices1050,
p_txtResponseText,
p_txtResponseErrorText,
p_codeCreatedDocNo}, this.ImportOrderOperationCompleted, userState);
}
private void OnImportOrderOperationCompleted(object arg) {
if ((this.ImportOrderCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.ImportOrderCompleted(this, new ImportOrderCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/>
public new void CancelAsync(object userState) {
base.CancelAsync(userState);
}
}
解决方案
在应用服务中使用证书有两个主要选项。两者都使用 Key Vault 将证书安全地存储在 Azure 中。
最简单的选择是将证书添加到您的应用服务帐户。可以在应用服务的SSL/TLS 屏幕中找到已安装的证书。如果您需要从代码内部访问它,请添加一个以WEBSITE_LOAD_CERTIFICATES
证书指纹命名的应用程序设置,如果您不知道该值,则在您上传它后将在门户中看到该设置。证书在文件系统中的位置取决于您是上传私有证书还是公共证书,以及您是在 Linux 还是 Windows 主机上:https ://docs.microsoft.com/en-us/azure/app-service /configure-ssl-certificate-in-code#load-certificate-in-linuxwindows-containers
您还可以将证书直接存储在 Key Vault 中,然后使用Key Vault Client检索它们。
var client = new CertificateClient(vaultUri: new Uri(keyVaultUrl), credential: new DefaultAzureCredential());
KeyVaultCertificateWithPolicy certificateWithPolicy = client.GetCertificate("MyCertificate");
推荐阅读
- python - 在 Python 3 中查找并获取未知大 RAM 分配的回溯
- python-3.x - Python3苹果mobileconfig下载服务器
- yugabyte-db - 主引导过程如何工作以及如何调试它?
- php - 如何使用 where 子句在 cakephp 中正确嵌套查询?
- reactjs - 从 yarn build 编辑静态文件(index.html)
- python - jupyter nbconvert:如何在不执行多次的情况下执行和输出多种格式?
- capacitor - “无法注入电容器”是什么意思,我该如何解决?
- python-3.x - 进行数字更改时,python多线程锁无法按预期工作
- javascript - Javascript Promise:为什么即使返回命令在函数内部,我也必须返回函数?
- javascript - 停止字符被插入输入反应