SoapCore Method ending with Response - soapcore

I have to recreate an old WCF project in .net 6.
There are methods such as:
UpdateIncident and UpdateIncidentResult
The UpdateIncident works fine, however the UpdateIncidentResult does not generate any detail
[OperationContract(IsOneWay = true)] void UpdateIncident(UpdateIncident UpdateIncident);
[OperationContract(IsOneWay = true)] void UpdateIncidentResponse(UpdateIncidentResponse UpdateIncidentResponse);

Related

Extend a Sha256 Test Certificate for ClickOnce

First, I know there are a lot of posts about clickonce test certificates renewal on OF but this is not the core of the question.
I have an internal clickonce app signed with a Test Certificate that expired.
We now need to deploy a new version but we don't want to force everyone to reinstall our app and risk them to lose personnal settings.
I tried using OceanAirdrop's ExtendClickOnceCertificate (a derivative from the original MS RenewCert application) but I always end up with a SHA1 certificate while the original one is SHA256. How can I get it (or any other renewal tool) to really make an extended clone of the original?
(The basic renewal problem was already discussed here. This question is about the renewal of a SHA256 certificate)
I made some changes in the Crypt.cs File to solve this issue.
First add this two struct:
[StructLayout(LayoutKind.Sequential)]
public struct CRYPT_ALGORITHM_IDENTIFIER
{
[MarshalAs(UnmanagedType.LPStr)]
public string pszObjId;
public CRYPTOAPI_BLOB parameters;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CRYPTOAPI_BLOB
{
public uint cbData;
public IntPtr pbData;
}
Then, modify the CertCreateSelfSignCertificate function like this:
[DllImport("Crypt32.dll", SetLastError = true, ExactSpelling = true)]
internal static extern IntPtr CertCreateSelfSignCertificate(
IntPtr providerHandle,
ref CRYPT_DATA_BLOB subjectIssuerBlob,
int flags,
IntPtr pinfo,
ref CRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
Native.SYSTEMTIME pStartTime,
Native.SYSTEMTIME pEndTime,
IntPtr extensions);
In Program.cs, before calling CertCreateSelfSignCertificate, add this:
Crypt.CRYPT_ALGORITHM_IDENTIFIER signatureAlgorithm = new Crypt.CRYPT_ALGORITHM_IDENTIFIER {
pszObjId = "1.2.840.113549.1.1.11"
};
Finally, change the call to the CertCreateSelfSignCertificate to look like this:
hCertContext = Crypt.CertCreateSelfSignCertificate(hCPContext, ref certNameBlob, 0,Info,ref signatureAlgorithm, null, certExpireDate, IntPtr.Zero);
And that is all. Compile the solution and run the command. This worked for me.

How to use AddDigitalSignatureOriginPart (DocumentFormat.OpenXml library) to secure an Excel file?

Need to create a digital signed excel file and then validate the signature when uploaded in C#.
On its own, the SpreadsheetDocument.AddDigitalSignatureOriginPart() method does not secure an Excel file. The same is true for the corresponding methods of the WordprocessingDocument and PresentationDocument classes. Those methods only add an empty DigitalSignatureOriginPart that serves as the origin of one or more XmlSignaturePart instances, each of which contains a ds:Signature element based on the W3C Recommendation XML Signature Syntax and Processing Version 1.1 (XMLDSIG).
To secure an Excel file, or any file based on the Open Packaging Conventions (OPC), the most straightforward approach is to use the PackageDigitalSignatureManager class, which is contained in the System.IO.Packaging namespace as provided by the WindowsBase.dll assembly. Thus, if you are targeting the full .NET Framework (e.g., net471), you can use it. However, if you are targeting .Net Core, you need to implement that functionality yourself.
The following code example shows how you can use the PackageDigitalSignatureManager class:
using System;
using System.Collections.Generic;
using System.IO.Packaging;
using System.Linq;
namespace CodeSnippets.Windows.IO.Packaging
{
public static class DigitalSignatureManager
{
public static void Sign(Package package)
{
var dsm = new PackageDigitalSignatureManager(package)
{
CertificateOption = CertificateEmbeddingOption.InSignaturePart
};
List<Uri> parts = package.GetParts()
.Select(part => part.Uri)
.Concat(new[]
{
// Include the DigitalSignatureOriginPart and corresponding
// relationship part, since those will only be added when
// signing.
dsm.SignatureOrigin,
PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin)
})
.ToList();
dsm.Sign(parts);
}
public static VerifyResult VerifySignature(Package package)
{
var dsm = new PackageDigitalSignatureManager(package);
return dsm.VerifySignatures(true);
}
}
}
In case you need to implement that functionality yourself, it helps to make yourself familiar with a number of sources:
The Digital Signing Framework of the Open Packaging Conventions
How to: Sign XML Documents with Digital Signatures
System.Security.Cryptography.Xml Namespace
Based on those sources, I created a partial sample implementation that works with .Net Core. The following snippet shows the void Sign(OpenXmlPackage, X509Certificate2) method that takes an OpenXmlPackage and an X509Certificate2 and creates a valid signature:
public static void Sign(OpenXmlPackage openXmlPackage, X509Certificate2 certificate)
{
if (openXmlPackage == null) throw new ArgumentNullException(nameof(openXmlPackage));
if (certificate == null) throw new ArgumentNullException(nameof(certificate));
RSA privateKey = certificate.GetRSAPrivateKey();
using SHA256 hashAlgorithm = SHA256.Create();
// Create KeyInfo.
var keyInfo = new KeyInfo();
keyInfo.AddClause(new KeyInfoX509Data(certificate));
// Create a Signature XmlElement.
var signedXml = new SignedXml { SigningKey = privateKey, KeyInfo = keyInfo };
signedXml.Signature.Id = Constants.PackageSignatureId;
signedXml.SignedInfo.SignatureMethod = Constants.SignatureMethod;
signedXml.AddReference(CreatePackageObjectReference());
signedXml.AddObject(CreatePackageObject(openXmlPackage.Package, hashAlgorithm));
signedXml.ComputeSignature();
XmlElement signature = signedXml.GetXml();
// Get or create the DigitalSignatureOriginPart.
DigitalSignatureOriginPart dsOriginPart =
openXmlPackage.GetPartsOfType<DigitalSignatureOriginPart>().FirstOrDefault() ??
openXmlPackage.AddNewPart<DigitalSignatureOriginPart>();
var xmlSignaturePart = dsOriginPart.AddNewPart<XmlSignaturePart>();
// Write the Signature XmlElement to the XmlSignaturePart.
using Stream stream = xmlSignaturePart.GetStream(FileMode.Create, FileAccess.Write);
using XmlWriter writer = XmlWriter.Create(stream);
signature.WriteTo(writer);
}
The full source code of the above void Sign(OpenXmlPackage, X509Certificate2) method can be found in my CodeSnippets GitHub repository. Look for the DigitalSignatureManager class in the CodeSnippets project.

PostSharp aspect not working when implement into assembly and calling that method

I have two three projects
1. framework
2. Repository
3. MVC Project
In framework project i implemented aspect
namespace FrameworkHelper.TestAspect
{
[Serializable]
[MulticastAttributeUsage(MulticastTargets.Method)]
public class CacheAspect : OnMethodBoundaryAspect
{
// This field will be set by CompileTimeInitialize and serialized at build time,
// then deserialized at runtime.
public string methodName;
// Method executed at build time.
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo)
{
this.methodName = method.DeclaringType.FullName + "." + method.Name;
}
// This method is executed before the execution of target methods of this aspect.
public override void OnEntry(MethodExecutionArgs args)
{
}
// This method is executed upon successful completion of target methods of this aspect.
public override void OnSuccess(MethodExecutionArgs args)
{
}
}
}
And aspect implemented into repository project
[TestAspect]
public List<string> TestMethod()
{
}
, When we calling method TestMethod() from MVC project , aspect not working , what's wrong on this code.
Its working fine when we use with one assembly.
I created new project for test the scanario and uploading project into github you can go through and can test home index controller.
https://github.com/virenderkverma/PostSharp-Examples
Project - PostSharpMultipleAssemblyCall
You can test this project
Sorry Daniel, Its working fine with latest version of postsharp , right now using
Postsharp of 3.1.50.9
Before i used 3.1.48 , May be that's problem with old version.
Thanks

CQ5(CRX) bookstore application error

I checked out source code fromhttp://dev.day.com/docs/en/crx/current/getting_started/first_steps_with_crx.html#Step%20Two:%20Check%20out%20CRX%20Bookstore%20Example
When I tried to invoke http://:4502/products.html
Actual result should list the products page from bookstore app
I got "Cannot serve request to /products.html in /apps/bookstore/components/ranking/ranking.jsp: What version of the product are you using? On what operating system?
I am using CQ5.5 (CRX 2.3) on windows 7
http://code.google.com/p/crxzon/issues/detail?id=4&thanks=4&ts=1362987616
From what I see, you get NullPointerException in RankingServiceImpl:277, because the repository field is null. And the only way I can explain that is that SCR annotations didn't fire during the build.
Said that, I'm actually surprised your bundle started on CQ 5.5, as the dependencies seem to be to earlier versions (5.4 I guess) -- I suggest double checking that under /system/console/bundles (search for CRX - Sample Bookstore Demo). If you're missing imports there, try playing with /src/impl/com.day.crx.sample.bookshop.bnd to update versions as in CQ 5.5, or running it on CQ 5.4.
The annotations in RankingServiceImpl seem to be for an earlier version of CQ and CRX. Here are the changes that I made to get this to work:
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
/**
* Default implementation of the ranking service.
* The ranking is updated through observation (based on OSGi events).
* The service can be used by clients to get the highest ranked products.
*/
#Component(immediate = true)
#Service(value = RankingService.class)
#Property(name = org.osgi.service.event.EventConstants.EVENT_TOPIC, value = SlingConstants.TOPIC_RESOURCE_ADDED)
public class RankingServiceImpl
implements RankingService, EventHandler, Runnable {
private Logger logger = LoggerFactory.getLogger(this.getClass());
// private Logger logger = LoggerFactory.getLogger("RankingServiceImpl");
private static final String PROPERTY_PREV_RANKING = "lowerRankingRef";
private static final String PROPERTY_NEXT_RANKING = "higherRankingRef";
private static final int SHOW_HIGHEST_RANKING = 3;
/** Flag for stopping the background service. */
private volatile boolean running = false;
/** A local queue for handling new orders. */
protected final BlockingQueue<String> orders = new LinkedBlockingQueue<String>();
#Reference
private SlingRepository repository;
#Reference
private ResourceResolverFactory resourceResolverFactory;

JDEdwards XMLInterop

Wondering if anybody out there has any success in using the JDEdwards XMLInterop functionality. I've been using it for a while (with a simple PInvoke, will post code later). I'm looking to see if there's a better and/or more robust way.
Thanks.
As promised, here is the code for integrating with JDEdewards using XML. It's a webservice, but could be used as you see fit.
namespace YourNameSpace
{
/// <summary>
/// This webservice allows you to submit JDE XML CallObject requests via a c# webservice
/// </summary>
[WebService(Namespace = "http://WebSite.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class JdeBFService : System.Web.Services.WebService
{
private string _strServerName;
private UInt16 _intServerPort;
private Int16 _intServerTimeout;
public JdeBFService()
{
// Load JDE ServerName, Port, & Connection Timeout from the Web.config file.
_strServerName = ConfigurationManager.AppSettings["JdeServerName"];
_intServerPort = Convert.ToUInt16(ConfigurationManager.AppSettings["JdePort"], CultureInfo.InvariantCulture);
_intServerTimeout = Convert.ToInt16(ConfigurationManager.AppSettings["JdeTimeout"], CultureInfo.InvariantCulture);
}
/// <summary>
/// This webmethod allows you to submit an XML formatted jdeRequest document
/// that will call any Master Business Function referenced in the XML document
/// and return a response.
/// </summary>
/// <param name="Xml"> The jdeRequest XML document </param>
[WebMethod]
public XmlDocument JdeXmlRequest(XmlDocument xmlInput)
{
try
{
string outputXml = string.Empty;
outputXml = NativeMethods.JdeXmlRequest(xmlInput, _strServerName, _intServerPort, _intServerTimeout);
XmlDocument outputXmlDoc = new XmlDocument();
outputXmlDoc.LoadXml(outputXml);
return outputXmlDoc;
}
catch (Exception ex)
{
ErrorReporting.SendEmail(ex);
throw;
}
}
}
/// <summary>
/// This interop class uses pinvoke to call the JDE C++ dll. It only has one static function.
/// </summary>
/// <remarks>
/// This class calls the xmlinterop.dll which can be found in the B9/system/bin32 directory.
/// Copy the dll to the webservice project's /bin directory before running the project.
/// </remarks>
internal static class NativeMethods
{
[DllImport("xmlinterop.dll",
EntryPoint = "_jdeXMLRequest#20",
CharSet = CharSet.Auto,
ExactSpelling = false,
CallingConvention = CallingConvention.StdCall,
SetLastError = true)]
private static extern IntPtr jdeXMLRequest([MarshalAs(UnmanagedType.LPWStr)] StringBuilder server, UInt16 port, Int32 timeout, [MarshalAs(UnmanagedType.LPStr)] StringBuilder buf, Int32 length);
public static string JdeXmlRequest(XmlDocument xmlInput, string strServerName, UInt16 intPort, Int32 intTimeout)
{
StringBuilder sbServerName = new StringBuilder(strServerName);
StringBuilder sbXML = new StringBuilder();
XmlWriter xWriter = XmlWriter.Create(sbXML);
xmlInput.WriteTo(xWriter);
xWriter.Close();
string result = Marshal.PtrToStringAnsi(jdeXMLRequest(sbServerName, intPort, intTimeout, sbXML, sbXML.Length));
return result;
}
}
}
You have to send it messages like the following one:
<jdeRequest type='callmethod' user='USER' pwd='PWD' environment='ENV'>
<callMethod name='GetEffectiveAddress' app='JdeWebRequest' runOnError='no'>
<params>
<param name='mnAddressNumber'>10000</param>
</params>
</callMethod>
</jdeRequest>
To anyone trying to do this, there are some dependencies to xmlinterop.dll.
you'll find these files on the fat client here ->c:\E910\system\bin32
this will create a 'thin client'
PSThread.dll
icudt32.dll
icui18n.dll
icuuc.dll
jdel.dll
jdeunicode.dll
libeay32.dll
msvcp71.dll
ssleay32.dll
ustdio.dll
xmlinterop.dll
I changed our JDE web service to use XML Interop after seeing this code, and we haven't had any stability problems since. Previously we were using the COM Connector, which exhibited regular communication failures (possibly a connection pooling issue?) and was a pain to install and configure correctly.
We did have issues when we attempted to use transactions, but if you're doing simple single business function calls this shouldn't be an problem.
Update: To elaborate on the transaction issues - if you're attempting to keep a transaction alive over multiple calls, AND the JDE application server is handling a modest number of concurrent calls, the xmlinterop calls start returning an 'XML response failed' message and the DB transaction is left open with no way to commit or rollback. It's possible tweaking the number of kernels might solve this, but personally, I'd always try to complete the transaction in a single call.