I have used the clr-namespace token to map a xaml namespace to a clr namespace as in
xamlns:local = "clr-namespace:mycompany.myproject"
In the above example, the local is mapped to mycompany.myproject.
I have seen the use of the token using in some code.
xamlns:local = "using:mycompany.myproject"
Is there any difference in behavior when using the token using compared to clr-namespace?
In WPF, Silverlight, Windows Phone xaml we use "clr-namespace" token to map a xaml namespace. Where as in Windows Store app (winrt) we use "using" token to map a xaml namespace.
Related
I cannot find the System.Security.Cryptography.RNGCryptoServiceProvider class in .NetCore.
It is essential to the application I am trying to port from .Net Framework, as it is being used to generate an initialisation vector for encryption.
Does it exist under a different name, or is there another way of achieving this functionality?
System.Security.Cryptography.RandomNumberGenerator is the base class for Cryptographically-Secure Pseudo-Random Number Generator (CSPRNG) implementations. In .NET Framework RandomNumberGenerator.Create() returns an RNGCryptoServiceProvider instance (unless configured differently by CryptoConfig). In .NET Core RandomNumberGenerator.Create() returns an opaque type which is based on BCryptGenRandom (Windows) or OpenSSL's random number generator (!Windows).
RandomNumberGenerator.Create() is the only way to get an RNG instance on .NET Core, and since it works on both .NET Core and .NET Framework is the most portable.
Of course, if you're generating an IV, you can also just call the instance method SymmetricAlgorithm.GenerateIV() to have it use the CSPRNG internally; though as the documentation says, calling it is unnecessary as a random IV is created with the instance (GenerateIV can be used to force it to generate a new one before the next call to CreateEncryptor).
One of the solutions suggested is to use RandomNumberGenerator.Create()
https://github.com/dotnet/corefx/issues/2881
We can do it like this in .Net core. It worked for me.
RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();
var byteArray = new byte[4];
provider.GetBytes(byteArray);
//convert 4 bytes to an integer
var randomInteger = BitConverter.ToUInt32(byteArray, 0);
It is present under the namespace : System.Security.Cryptography
add this in your class to use the method :
using System.Security.Cryptography;
Hope it is Helpful.
Thanks
I have existing code that uses System.Configuration.Provider namespace for provider collections to plugin various implementations of interfaces, where multiple implementations exist in the collection and are selected by name according to various logic.
This namespace is not available in .net core, so I'm looking for advice on how to implement a replacement solution that will work with .net core framework.
I know that if I was just trying to plugin one implementation, I could do it by dependency injection. But I'm looking for a way to have multiple implementations available to choose based on name.
My current implementation with provider model populates the provider collection from a folder where you can drop in xml files that declare the type of the actual implementations, so new implementations of the provider can be loaded from an assembly by just adding another file to the folder. I'd like to keep the logic as similar as possible to that but I'm open to json files rather than xml.
I am thinking I could load up a collection of implementations of the interface from json files in Startup and use dependency injection to provide the collection where needed or perhaps an interface that can get the collection would be lighter weight and allow getting them when they are needed rather than at startup.
Is that the right approach? Anyone have better ideas or done something similar?
This is done more generically than using an abstract base class like ProviderBase in the new framework. You can register multiple of the same service with the DI framework and get them all either simply by asking for an IEnumerable<> of the type you register them as or using the GetRequiredServices<> extension method. Once you get your services, however, you'll need some other way of distinguishing them, such as a property indicating a unique name, which is the pattern the ASP.Net team has been following.
You can see an example in the Identity framework v3 with the Token Providers.
IUserTokenProvider<T>, the "provider"
UserManager, which consumes the token managers
I'm trying to move all the calls I make to webservices to an Portable Class Library (PCL) that I've just created to organize and reuse my code. The frameworks I'm targeting to are .NET for Windows Store apps; .NET Framework 4.5; Silverlight 4 and higher and WP7 and higher.
On my Win RT project I've been setting up the message headers by implementing the IClientMessageInspector interface available in the namespace System.ServiceModel.Dispatcher. But on my PCL project that interface as well as System.ServiceModel.Description.IEndpointBehavior are not available.
So I need to find out how to attach a message header / service header to my service calls from a PCL project with those targeted frameworks. Anyone has experience and/or suggestions that I should try?
Update
Just for adding more info, I've tried to create a WP8 project now and noticed that those interfaces are not available for it either. So IClientMessageInspector and IEndpointBehavior are probably not available for my PCL project because it is targeting WP8 which misses them itself.
You should be able to scope the OperationContext to the current client channel you want to work with:
using(var scope = new OperationContextScope(_client.InnerChannel)){
//More to come
}
Now that you have the operation context created for your client channel, you can add outgoing message headers:
using(var scope = new OperationContextScope(_client.InnerChannel)){
var header = MessageHeader.CreateHeader("x-client-type", "http://www.myapp.com", "WP8");
OperationContext.Current.OutgoingMessageHeaders.Add(header);
//Send message to server
}
After that, you should be able to get the header using the IncomingMessageHeaders property of the OperationContext.Current.
These are all core pieces of WCF services, so it should be available (hopefully).
Mono does have support for WCF services, but you would have to check on what they have implemented. EG: Perhaps they don't have MessageHeader.Create and you would have to use var header = new MessageHeader<string>("x-client-type"); and var untypedHeader = header.GetUntypedHeader("x-client-type", "http://www.myapp.com"); instead to create your header to add.
I have a WCF Service running SOAP and allowing Flex / Flash to connect to it using basicHttpBinding by using the 'Data' \ 'Import Web Service' option. Unfortunately when I consume and invoke this service within Flex it throws the following error...
Error: Cannot find definition for type
'http://schemas.datacontract.org/2004/07/System.Drawing::Size' at
mx.rpc.xml::XMLDecoder/decodeType()
...when using the following code...
// This will return an array of presentations
var service:PresentationAuthoring = new PresentationAuthoring();
var token:AsyncToken = service.getAllPresentationByClientId(
mClientId , mUserId , mWCFServiceHash );
token.addEventListener( ResultEvent.RESULT, onResult );
token.addEventListener( FaultEvent.FAULT, onFault );
This method returns an array of Presentation objects that are retreived by the service. At the moment there are no DataContracts and I'm allowing the POCO Presentation object to be serialised and punted out by the service that works fine. However, this class has a readonly property of the type System.Drawing.Size that derived from appropriate height and width properties. Looking through the generated code, it doesn't register a 'Size' class in the base import schema although it still seems to create a Size class.
An alternative has been to stop the derived property from being serialised using the [XmlIgnore] but that has not worked.
Ideally, I need a way of allowing my Flex application to communicate with my WCF service but it seems to choke on the System.Drawing.Size type and while I could change this, there are other framework types such as Point, Rectangle, etc, etc. that are utilised within the project. Has anyone else experienced this problem or can suggest an alternative approach to take?
[Please note that the WCF Service functions correctly when a .NET application consumes it.]
Kind regards and thanks in advance - S
Well the answer was to box the Size struct with a custom class that worked perfectly although it is somewhat irksome I might have to do this with (potentially) other native drawing structs. Ho hum.
My domain service has invoke operation method and returns a custom
type say 'User'. This class has many properties such as String,
Integer, Boolean, XElement. When I rebuild the solution to generate
client-side proxy, it generates code for the class User in the client
for all the properties, except for XElement. What is the fix for this?
Will RIA not generate any code for XNode or XElement types? Should
these elements be converted to String? Are there any fixes for this
error?
I'm using VS2010 SP1, .Net Framework 4, WCF RIA, Silverlight 5.
According to the Silverlight DataContract documentation, you can mark your classes as either opt-in using the DataContract/DataMember attributes or opt-out and rely on only serializing public scope class members. You need to show the code of the class you're having problems with to get better suggestions.