我有一个工作代码,其中来自MSSQL db的数据用于使用SSIS的脚本组件通过wsdl文件流至SAP Bapiret2私有服务引用。
该代码适用于INT,QA和Stage环境。所有这些环境均具有不同的端点地址和要在IIS上安装的证书。
EngagementName和LocalClientName列被选为BlobColumn。
我得到的错误是:
接收到https://s ***。######。com / **** Gateway的HTTP响应时发生错误。这可能是由于服务端点绑定未使用HTTP协议。这也可能是由于服务器终止了HTTP请求上下文(可能是由于服务关闭了)。有关更多详细信息,请参见服务器日志。
基础连接已关闭:服务器已关闭了预期保持活动状态的连接。
请求通道在00:20:00之后等待答复时超时。增加传递给请求的调用的超时值,或者增加绑定上的SendTimeout值。分配给该操作的时间可能是较长超时的一部分。
我以前在较早的环境中没有收到错误,但是现在对于某些行,我得到了高于错误的消息。整个程序包曾经在20分钟内成功运行,但是现在由于错误,它继续运行,因此我必须手动停止它。
对于解决方案,我将KeepAlive属性设置为false,但这增加了包运行的时间,但仍然出现其他错误。
此外,通过Google搜索,我在BufferWrapper.cs文件中为所有getter setter属性添加了[DataContract]和[DataMember],但无济于事。 但是当我重新打开.cs文件时,它又变回了没有[DataContract]和[DataMember]的早期版本。
还已将超时时间从20分钟更改为10分钟,但没有喘息的机会。
我在脚本组件中的代码如下:
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
using SC_33acc229408b4ba595c36ca01338cfef.****_engagement_service;
using System.ServiceModel;
using System.Data.SqlClient;
using System.Net;
using Microsoft.Web.Administration;
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
String sSystemID = String.Empty;
String sCert = String.Empty;
String sEndPointAddress = String.Empty;
String sCustomProvider = string.Empty;
public override void PreExecute()
{
base.PreExecute();
/*
* Add your code here
*/
sSystemID = this.Variables.UserID;
sEndPointAddress = this.Variables.EndPointAddress;
sCert = this.Variables.CertID.ToUpper();
sCustomProvider = this.Variables.EngCustomBinding;
}
public override void PostExecute()
{
base.PostExecute();
/*
* Add your code here
*/
}
/// Example of reading a value from a column in the the row:
/// string zipCode = Row.ZipCode
///
/// Example of writing a value to a column in the row:
/// Row.ZipCode = zipCode
/// </summary>
/// <param name="Row">The row that is currently passing through the component</param>
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
System.ServiceModel.Channels.TextMessageEncodingBindingElement textMessage = new System.ServiceModel.Channels.TextMessageEncodingBindingElement()
{
MessageVersion = System.ServiceModel.Channels.MessageVersion.Soap12
};
System.ServiceModel.Channels.HttpsTransportBindingElement httpTransport = new System.ServiceModel.Channels.HttpsTransportBindingElement();
//ServicePointManager.Expect100Continue = true; //mine
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; //mine
httpTransport.ManualAddressing = false;
httpTransport.MaxBufferPoolSize = 2147483647;
httpTransport.MaxReceivedMessageSize = 2147483647;
httpTransport.AllowCookies = false;
httpTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous;
httpTransport.BypassProxyOnLocal = true;
httpTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
httpTransport.KeepAliveEnabled = true;
httpTransport.MaxBufferSize = 2147483647;
httpTransport.ProxyAuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous;
httpTransport.Realm = String.Empty;
httpTransport.TransferMode = TransferMode.Buffered;
httpTransport.UnsafeConnectionNtlmAuthentication = false;
httpTransport.RequireClientCertificate = true;
//customBinding.Elements.Add(httpTransport);
System.ServiceModel.Channels.CustomBinding customBinding = new System.ServiceModel.Channels.CustomBinding(textMessage, httpTransport);
customBinding.Name = sCustomProvider;
customBinding.CloseTimeout = new TimeSpan(0, 10, 0);
customBinding.OpenTimeout = new TimeSpan(0, 10, 0);
customBinding.ReceiveTimeout = new TimeSpan(0, 10, 0);
customBinding.SendTimeout = new TimeSpan(0, 10, 0);
EndpointAddress endPointAddress = new EndpointAddress(new Uri(sEndPointAddress)); //endpointaddress fr�n parameter
X509Certificate2 _cert = new X509Certificate2();
//_cert = _GetClientCertificate(StoreLocation.CurrentUser, sCert);
_cert = _GetClientCertificate(StoreLocation.LocalMachine, sCert);
//X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
//_cert = _GetClientCertificate(store.Location, sCert); //mine
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HeaderRequestType header = new HeaderRequestType()
{
SystemID = sSystemID, //H�mtas fr�n parameter UserID
UserID = ""
};
string sCon = Connections.dbconn.ConnectionString;
sCon = sCon.Replace("Provider=SQLNCLI11.1;", "");
sCon = sCon.Replace("Auto Translate=False;", "");
ZmrfmMfEngProviderResponse response = new ZmrfmMfEngProviderResponse();
ZmrfmMfEngProvider req = new ZmrfmMfEngProvider();
req.ItEngagement = new ZmrsMfProvider[]
{
new ZmrsMfProvider()
{
Mfid = Row.MemberFirmID,
EngCode = Row.EngagementCode,
LclClntId = Row.LocalClientID,
//EngName = Row.EngagementName,
EngName = System.Text.Encoding.Unicode.GetString(Row.EngagementName.GetBlobData(0, Convert.ToInt32(Row.EngagementName.Length))),
//LclClntName = Row.LocalClientName,
LclClntName = System.Text.Encoding.Unicode.GetString(Row.LocalClientName.GetBlobData(0, Convert.ToInt32(Row.LocalClientName.Length))),
EngCountry = Row.EngagementCountry,
EngIndSector = Row.EngagementIndustrySector,
EngmntLead = Row.EngagementLead,
EngmntManager = Row.EngagementManager,
Active = Row.ActiveFlag,
}
};
String sEngCode = req.ItEngagement[0].EngCode;
String sMFID = req.ItEngagement[0].Mfid;
try
{
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate (object sender, X509Certificate certx, X509Chain chain, SslPolicyErrors sslError)
{
return true;
};
zmrsv_engproviderClient c = new zmrsv_engproviderClient(customBinding, endPointAddress);
c.ClientCredentials.ClientCertificate.Certificate = _cert;
var resp = c.ZmrfmMfEngProvider(ref header, req);
response = (ZmrfmMfEngProviderResponse)resp;
System.Text.StringBuilder sMessage = new System.Text.StringBuilder();
sMessage.Append(response.ItReturn[0].Message);
sMessage.Append(response.ItReturn[0].MessageV1);
sMessage.Append(response.ItReturn[0].MessageV2);
sMessage.Append(response.ItReturn[0].MessageV3);
sMessage.Append(response.ItReturn[0].MessageV4);
System.Text.StringBuilder sSql = new System.Text.StringBuilder();
sSql.Append("INSERT INTO [****].[dbo].[Engagements_log]([Mfid],[Engagement_code],[Date],[ResponseMessage]) ");
sSql.Append("select '" + sMFID + "', '" + sEngCode + "', '" + DateTime.Now.ToString() + "', ");
sSql.Append("'" + sMessage.ToString() + "'");
using (SqlConnection conn = new SqlConnection(sCon))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(sSql.ToString(), conn))
{
cmd.ExecuteNonQuery();
}
conn.Close();
}
}
catch (Exception ex)
{
System.Text.StringBuilder strSQL = new System.Text.StringBuilder();
strSQL.Append("insert into [****].[dbo].Engagements_Error_log([Mfid],[EngagementCode],[Date],[ErrorMessage])");
strSQL.Append(" select '" + sMFID + "', '" + sEngCode + "', ");
strSQL.Append("'" + DateTime.Now.ToString() + "', @msg");
using (SqlConnection conn = new SqlConnection(sCon))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(strSQL.ToString(), conn))
{
cmd.Parameters.AddWithValue("@msg", ex.Message);
cmd.ExecuteNonQuery();
}
conn.Close();
}
strSQL.Length = 0;
}
}
private X509Certificate2 _GetClientCertificate(StoreLocation storeLocation, string serialNumber)
{
X509Store store = new X509Store(storeLocation);
store.Open(OpenFlags.ReadOnly);
string newbindinginformation = "*:443:";
int bindingIndex = 0;
try
{
foreach (X509Certificate2 cert in store.Certificates)
{
if (cert.FriendlyName == "StagingCertificateName.com")
{
using (ServerManager serverManager = new ServerManager())
{
Site site = serverManager.Sites["Default Web Site"];
if (site != null)
{
foreach (Microsoft.Web.Administration.Binding binding in site.Bindings)
{
if (binding.BindingInformation == newbindinginformation)
{
bindingIndex = site.Bindings.IndexOf(binding);
}
}
if (bindingIndex != -1)
{
site.Bindings.RemoveAt(bindingIndex);
}
site.Bindings.Add("*:443:", cert.GetCertHash(), store.Name);
//ManagementUnit.Update();
}
}
return cert;
}
}
throw new ArgumentException();
}
finally
{
store.Close();
}
}
}
App.config中的代码是:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="ZMRSV_ENGPROVIDER_soap12">
<!-- WsdlImporter encountered unrecognized policy assertions in ServiceDescription 'urn:sap-com:document:sap:soap:functions:mc-style': -->
<!-- <wsdl:binding name='ZMRSV_ENGPROVIDER_soap12'> -->
<!-- <sapattahnd:Enabled xmlns:sapattahnd="http://www.sap.com/710/features/attachment/">..</sapattahnd:Enabled> -->
<mtomMessageEncoding />
<httpsTransport requireClientCertificate="true" />
</binding>
</customBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="zmrsv_engprovider_int">
<clientCredentials>
<clientCertificate findValue="ST*************.de*******urces.com" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My"/>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="https://****.######.com/****Gateway" behaviorConfiguration="zmrsv_engprovider_int" binding="customBinding"
bindingConfiguration="ZMRSV_ENGPROVIDER_soap12" contract="****_engagement_service.zmrsv_engprovider"
name="ZMRSV_ENGPROVIDER_soap12" />
</client>
</system.serviceModel>
</configuration>
请检查并找出问题所在。
任何帮助将不胜感激。