VersionOne Unknown AssetType - c#

I'm trying to use the VersionOne API via the C# APIClient, but my meta model is only getting an Unknown AssetType error wrapping a 405 exception. What am I doing wrong? Here's a code snippet:
VersionOneAPIConnector conn = VersionOneClientFactory.CreateClient(Endpoint.Data);
conn.WithVersionOneUsernameAndPassword("username", "password");
IMetaModel meta = new MetaModel(VersionOneClientFactory.CreateClient(Endpoint.Meta));
Services s = new Services(meta, conn);
If it helps, here's the CreateClient method:
public static VersionOneAPIConnector CreateClient(Endpoint e)
{
StringBuilder url = new StringBuilder("https://www#.v1host.com/MyCompany/");
switch (e)
{
case Endpoint.Data: url.Append("rest-1.v1"); break;
case Endpoint.Localization: url.Append("loc-2.v1"); break;
case Endpoint.Meta: url.Append("meta.v1"); break;
case Endpoint.Query: url.Append("query.v1"); break;
}
return new VersionOneAPIConnector(
url.ToString(),
proxyProvider: new ProxyProvider(
new Uri("http://proxy.server"),
"proxy_username",
"proxy_password"
));
}
Here's what I see in Visual Studio:
In this case I use a breakpoint to show you the issues in the Locals window. If I were to actually try to do anything, the MetaException gets thrown.

I tried your code and ran into the same issue. I was able to make it work by adding a "/" at the end of each endpoint (the meta endpoint in particular). Could you try that?

This seems to fix it:
proxyProvider: new ProxyProvider(
new Uri("https://proxy.server:port"),
"proxy_username",
"proxy_password"
)
I could've sworn whatever example I was using said to not include port. Apparently that was fallacious. Sorry for the trouble guys, but thanks for trying to help!
Also, verified that mkunzi's answer is valid too. You need the slashes at the end of the endpoints (e.g. "meta.v1/") or it won't work.

Related

Making a security definition request to FIX adapter

I am trying to make a request (Security Definition Request) to FIX Adapter using the following method. This is an application level call and I manually invoke this method whenever there is a successful connection to FIX Adapter.
WHen i run this method i get a "Field not found for tag:49" exception message. However SecurityDefinitionRequest class doesnt allow me to set Tag 49 (SenderCompId) to it.
First of all is this the right way to make a SecurityDefinitionRequest? I tried looking at QuickFix/N docs but they dont explain how to make such request.
http://quickfixn.org/tutorial/sending-messages.html
Infact i havent seen any articles so far in the internet. Any suggestions?
public void ToApp(Message message, SessionID sessionId)
{
var request =
new SecurityDefinitionRequest()
{
SecurityReqID = new SecurityReqID("1"),
SecurityID = new SecurityID("5"),
SecurityRequestType = new SecurityRequestType(3),
SecurityType = new SecurityType("FUT")
};
request.SetField(new SenderCompID("217"));
Session.SendToTarget(request);
}
The constructed message looks like this
8=FIX.4.29=3735=c48=549=217167=FUT320=1321=310=003
I'm going to suggest:
SessionId currentSessionId = new QuickFix.SessionID("FIX4.2", "217","CBOE");
securityDefinitionRequest.SetSessionID(currentSessionId );

Twilio StatusCallback not working:

So I'm building an app with twilio voice, and I've got all the phonecall stuff working. But I'm having a little trouble understanding which parameters my callback should have.
I've registered the URL as described in the docs:
options.From = formatPhoneNumber(callout.callback_number);
options.To = formatPhoneNumber(offer.employee_phone_number);
options.Url = TwilioCallBotController.TwilioCalloutScriptURL;
options.StatusCallback = TwilioCallBotController.StatusCallbackURL;
options.StatusCallbackEvents = new []{"initiated", "ringing", "answered", "completed" };
options.StatusCallbackMethod = "POST";
I've also made a callback method here, but I'm not having much luck finding out how the parameters are supposed to work with their API. I'm kindof at a loss as to what could be the reason behind this one not working:
[HttpPost]
public ActionResult TwilioStatusCallback()
{
var twiml = new Twilio.TwiML.TwilioResponse();
twiml.Say("This is a test");
string CallSid = Request.Form["CallSid"];
string CallStatus = Request.Form["CallStatus"];
Debug.WriteLine("Status Callback Delivered");
Shift_Offer shoffer = db.Shift_Offers.Where(s => s.twillio_sid == CallSid).ToList()[0];
shoffer.status = CallStatus.ToString();// + DateTime.Now.ToString();
return TwiML(twiml);
}
Edit:
So it turns out that the API is very sensitive about the method signature (the call was previously throwing a method not found exception in a number of microsoft DLLs, including System.Web and System.Web.Mvc.
So I've actually gotten the software to call the method by using an empty method signature (no parameters).
However I'm still having trouble getting the parameters from the HTTPPOST
Edit: So upon further investigation I've managed to inspect the Request. The values I'm after exist in Request.Form["foo"], but they don't seem to be getting put into the two strings I have declared. I've removed the ["HttpPost"] attribute to try to troubleshoot the issue, but I'm really at a loss as to why I can see the values in the debugger, but they're not translating into memory.
public ActionResult TwilioStatusCallback()
{
var twiml = new Twilio.TwiML.TwilioResponse();
string sid = Request.Form["CallSid"];
string status = Request.Form["CallStatus"];
Shift_Offer shoffer = db.Shift_Offers.Where(s => s.twillio_sid == sid).ToList()[0];
shoffer.status = status;// + DateTime.Now.ToString();
return TwiML(twiml);
}
Last issue was that the database wasn't being saved.
Just added a db.SaveChanges() and we're good.

NBitcoin throws InvalidOperationException with the message: "Mac HMACSHA256 not recognised."

I got the message when I try to sign a transaction:
Transaction payment = new Transaction();
BitcoinSecret PaymentSecret = new BitcoinSecret("1sXCvdpXz...UqkXW9mvT");
...
payment.Sign(Container.PaymentSecret, false);
I dig into the opensource NBitcoin API and figured out these lines give me the error message. What can I do? (https://github.com/NicolasDorier/NBitcoin/blob/master/NBitcoin/Crypto/DeterministicECDSA.cs)
try
{
hmac = MacUtilities.GetMac(macName);
}
catch(SecurityUtilityException nsae)
{
throw new InvalidOperationException(nsae.Message, nsae);
}
If someone would like to figure out what is happening exactly, here's a code snippet that'll cause the bug:
string mechanism = "HMACSHA256";
if (mechanism.StartsWith("HMAC"))
{
Console.WriteLine("good");
}
else
{
Console.WriteLine("bad");
}
Console.ReadLine();
If you set mechanism = "HMAC-SHA256", then the bug won't happen.
If you use mechanism.StartsWith("HMAC",StringComparison.InvariantCulture), then bug won't happen.
I've also fixed the bug in github and created a pull request to the NBitcoin API, so hopefully it won't happen with others in the future.
The problem was here:
NBitcoin/NBitcoin.BouncyCastle/security/MacUtilities.cs
public static IMac GetMac(string algorithm)
{
...
if(mechanism.StartsWith("HMAC"))
{
...
}
...
}
The mechanism string is "HMACSHA256" and the if statement never evaluates true for me, because my language is Hungarian and "CS" is a letter in Hungarian. So according to the StartsWith function "HMACSHA256" doesn't start with "HMAC" in Hungarian.
The issue has been fixed in the NBitcoin API by Nicolas Dorier as adding StringComparison.OrdinalIgnoreCase setting to the StartWith function.
In case someone wants to test it, here's an email from Nicolas:
Ok, for history.
Thread.CurrentThread.CurrentCulture = new CultureInfo("hu");
string mechanism = "HMACSHA256";
var v1 = mechanism.StartsWith("HMAC");
mechanism = "HMAC-SHA256";
var v2 = mechanism.StartsWith("HMAC");
In hungarian, v1 is false and v2 true.
There is a hyphen after HMAC. HMAC-SHA256
I just tried the code on my machine, and it works perfectly.
public void CanSignSimple()
{
Key bob = new Key();
Transaction tx = new Transaction();
tx.Inputs.Add(new TxIn()
{
ScriptSig = bob.ScriptPubKey
});
tx.Sign(bob, false);
}
It should be noted that I am not using Bouncy castle library now. I copied the needed part of bouncycastle INSIDE NBitcoin.
Your bug seems like you are using NBitcoin along with the official BouncyCastle, which can happen only if you recompiled everything yourself with using the official BouncyCastle lib, OR you are using an old version of NBitcoin.
What version are you using ?

c# CommandLine.Parser - Use constructor that accepts Action<ParserSettings>

I was using this code, but I am getting a compiler warning that this method of creation is deprecated. As I want to remove the warning, and move to the newer version, I want to correct the code, but I can not get the CommandLineParser 1.9.7 library to work.
CommandLine.Parser OptionParser = new CommandLine.Parser(new CommandLine.ParserSettings
{
CaseSensitive = UseCaseSensitive,
IgnoreUnknownArguments = IgnoreUnknownOptions,
MutuallyExclusive = EnableMutuallyExclusive
}
);
bool Result = OptionParser.ParseArguments(Args, this);
This code works and Result would be True/False based on the parameters of the command line and options passed. However, the following warning is posted.
Warning 1 'CommandLine.Parser.Parser(CommandLine.ParserSettings)' is obsolete: 'Use constructor that accepts Action<ParserSettings>.'
The Online help shows this as an example for using the function.
new CommandLine.Parser(configuration: () => new CommandLine.ParserSettings(Console.Error))
I tried changing the code, but I am not getting the Lambda right, and am not sure how to get this to work. While the code executes, I only get the default functions, I can not seem to change the Case Sensitive, Mutually Exclusive, etc... options.
Line using the Constructor (from the inline IDE help)
bool Result = new CommandLine.Parser(configuration: (Settings) => new CommandLine.ParserSettings(UseCaseSensitive, EnableMutuallyExclusive, IgnoreUnknownOptions, null)).ParseArguments(Args, this);
Trying again with the virtual settings:
bool Result = new CommandLine.Parser(configuration: (Settings) => new CommandLine.ParserSettings
{
CaseSensitive = UseCaseSensitive,
IgnoreUnknownArguments = IgnoreUnknownOptions,
MutuallyExclusive = EnableMutuallyExclusive
}
).ParseArguments(Args, this);
The online help has not kept up with the tool, and I could use any pointers someone might have. Thanks in advance...
Looking at the source code the constructor runs that Action passed on new settings that it creates:
public Parser(Action<ParserSettings> configuration)
{
if (configuration == null) throw new ArgumentNullException("configuration");
this.settings = new ParserSettings();
configuration(this.settings);
this.settings.Consumed = true;
}
So in the Action<ParserSettings> you should set the values you want on the parameter, not create new settings (remember that an Action<T> is a prototype for a function that takes a T and does not return a value):
var parser = new CommandLine.Parser( s =>
{
s.CaseSensitive = UseCaseSensitive;
} );
NOTE: The source code I linked to does not appear to be the same version as you are using since Parser( ParserSettings ) is marked internal in the source I found, which means you wouldn't even be able to call it, and some of the ParserSettings properties do not appear in the version I found. However, I believe this answer applies to the version you have as well.

sending a SOAP request with c#

I'm trying to send a SOAP request to a 3rd party web service. I've successfully send and received data from other interfaces in the same service, but I'm having problems with this particular one:
<SP_GoodsMovement xmlns="http://services.hnseu.com">
<GoodsMoved xmlns="http://tempuri.org/SP_GoodsMoved.xsd">
<SerialNumberedGoodsMovements>
<SerialNumbered>
<PartNumber>string</PartNumber>
<SerialNumber>string</SerialNumber>
<MovementType>string</MovementType>
<FromLocation>string</FromLocation>
<FromLocationCategory>string</FromLocationCategory>
<ToLocation>string</ToLocation>
<ToLocationCategory>string</ToLocationCategory>
<AssetMovementTimestamp>dateTime</AssetMovementTimestamp>
<GoodsInReference>string</GoodsInReference>
</SerialNumbered>
<SerialNumbered>
<PartNumber>string</PartNumber>
<SerialNumber>string</SerialNumber>
<MovementType>string</MovementType>
<FromLocation>string</FromLocation>
<FromLocationCategory>string</FromLocationCategory>
<ToLocation>string</ToLocation>
<ToLocationCategory>string</ToLocationCategory>
<AssetMovementTimestamp>dateTime</AssetMovementTimestamp>
<GoodsInReference>string</GoodsInReference>
</SerialNumbered>
</SerialNumberedGoodsMovements>
<NonSerialNumberedGoodsMovements>
<NonSerialNumbered>
<PartNumber>string</PartNumber>
<Quantity>unsignedInt</Quantity>
<MovementType>string</MovementType>
<FromLocation>string</FromLocation>
<FromLocationCategory>string</FromLocationCategory>
<ToLocation>string</ToLocation>
<ToLocationCategory>string</ToLocationCategory>
<Used>boolean</Used>
<AssetMovementTimestamp>dateTime</AssetMovementTimestamp>
<GoodsInReference>string</GoodsInReference>
</NonSerialNumbered>
<NonSerialNumbered>
<PartNumber>string</PartNumber>
<Quantity>unsignedInt</Quantity>
<MovementType>string</MovementType>
<FromLocation>string</FromLocation>
<FromLocationCategory>string</FromLocationCategory>
<ToLocation>string</ToLocation>
<ToLocationCategory>string</ToLocationCategory>
<Used>boolean</Used>
<AssetMovementTimestamp>dateTime</AssetMovementTimestamp>
<GoodsInReference>string</GoodsInReference>
</NonSerialNumbered>
</NonSerialNumberedGoodsMovements>
</GoodsMoved>
</SP_GoodsMovement>
so my code is as follows (i can expand this if necesssary):
...
if (requestType == "SP_GoodsMovement")
{
GoodsMoved SOAP_GoodsMoved = new GoodsMoved();
SOAP_GoodsMoved.SerialNumberedGoodsMovements[0].PartNumber = partNumber[0].InnerXml;
...
string SOAPMessage;
SOAPMessage = request.SP_GoodsMovement(header, SOAP_GoodsMoved).Message;
}
When I run this code I get an 'Object reference not set to an instance of an object' error.
I think i'm not referencing the PartNumber parameter properly, but i've tried a few things without success.
Any ideas?
SOAP_GoodsMoved.SerialNumberedGoodsMovements[0]
doesn't appear to be initialised.
maybe try
GoodsMoved SOAP_GoodsMoved = new GoodsMoved();
SOAP_GoodsMoved.SerialNumberedGoodsMovements = new WhateverObject[1];
SOAP_GoodsMoved.SerialNumberedGoodsMovements[0] = new WhateverObject();
SOAP_GoodsMoved.SerialNumberedGoodsMovements[0].PartNumber = partNumber[0].InnerXml;
or you could right an overload for your GoodsMoved() ctor that ensures that the SerialNumberedGoodsMovements array gets initialized with a certain size.

Categories

Resources