IotaInsanity
Junior Member
- Oct 24, 2013
- 129
- 16
Long shot here, but is anyone able to help me out. I have this API im tyring to access in c# and a coldfusion example.
I'm trying to make a call to a url to get a json object returned.
I have an example in coldfusion i am trying to use to base it off of.
Test For IPCorg123: (the return should: Hello World)<br>
<cfinvoke method="test20130401" returnvariable="rawReturn"
webservice="https://secure.test.com/webservices/ws_users.cfc?wsdl">
<cfinvokeargument name="accountlogincode" value="1"/>
<cfinvokeargument name="accountxmlcode" value="1"/>
<cfinvokeargument name="accountidspecialcode" value="1"/>
<cfinvokeargument name="authorlogin" value="1"/>
<cfinvokeargument name="authorpassword" value="1"/>
<cfinvokeargument name="TestString" value="Hello World/>
</cfinvoke>
<cfdump var="#rawReturn#"><br><br><br><br>
Done!
I'm trying to convert this to c# and heres what I have.
class Program
{
public static string accountlogincodename = "accountlogincodevalue";
public static string accountxmlcodename = "accountxmlcodevalue";
public static string accountidspecialcodename = "accountidspecialcode";
public static string authorloginname = "authorlogin";
public static string authorpasswordname = "authorpassword";
public static string TestStringname = "TestString";
public static string accountlogincodevalue = "1";
public static string accountxmlcodevalue = "1";
public static string accountidspecialcodevalue = "1";
public static string authorloginvalue = "1";
public static string authorpasswordvalue = "1";
public static string TestStringvalue = "Hello";
static void Main()
{
RunAsync().Wait();
}
static async Task RunAsync()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://secure.test.com/webservices/ws_users.cfc?wsdl");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpRequestMessage m = new HttpRequestMessage();
m.Properties.Add(accountlogincodename, accountlogincodevalue);
m.Properties.Add(accountxmlcodename, accountxmlcodevalue);
m.Properties.Add(accountidspecialcodename, accountidspecialcodevalue);
m.Properties.Add(authorloginname, authorloginvalue);
m.Properties.Add(authorpasswordname, authorpasswordvalue);
m.Properties.Add(TestStringname, TestStringvalue);
// New code:
HttpResponseMessage response = await client.SendAsync(m);
if (response.IsSuccessStatusCode)
{
var x = await response.Content.ReadAsStringAsync();
}
}
}
}
I'm not getting the expected result back, which is just "Hello World"
I'm trying to make a call to a url to get a json object returned.
I have an example in coldfusion i am trying to use to base it off of.
Test For IPCorg123: (the return should: Hello World)<br>
<cfinvoke method="test20130401" returnvariable="rawReturn"
webservice="https://secure.test.com/webservices/ws_users.cfc?wsdl">
<cfinvokeargument name="accountlogincode" value="1"/>
<cfinvokeargument name="accountxmlcode" value="1"/>
<cfinvokeargument name="accountidspecialcode" value="1"/>
<cfinvokeargument name="authorlogin" value="1"/>
<cfinvokeargument name="authorpassword" value="1"/>
<cfinvokeargument name="TestString" value="Hello World/>
</cfinvoke>
<cfdump var="#rawReturn#"><br><br><br><br>
Done!
I'm trying to convert this to c# and heres what I have.
class Program
{
public static string accountlogincodename = "accountlogincodevalue";
public static string accountxmlcodename = "accountxmlcodevalue";
public static string accountidspecialcodename = "accountidspecialcode";
public static string authorloginname = "authorlogin";
public static string authorpasswordname = "authorpassword";
public static string TestStringname = "TestString";
public static string accountlogincodevalue = "1";
public static string accountxmlcodevalue = "1";
public static string accountidspecialcodevalue = "1";
public static string authorloginvalue = "1";
public static string authorpasswordvalue = "1";
public static string TestStringvalue = "Hello";
static void Main()
{
RunAsync().Wait();
}
static async Task RunAsync()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://secure.test.com/webservices/ws_users.cfc?wsdl");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpRequestMessage m = new HttpRequestMessage();
m.Properties.Add(accountlogincodename, accountlogincodevalue);
m.Properties.Add(accountxmlcodename, accountxmlcodevalue);
m.Properties.Add(accountidspecialcodename, accountidspecialcodevalue);
m.Properties.Add(authorloginname, authorloginvalue);
m.Properties.Add(authorpasswordname, authorpasswordvalue);
m.Properties.Add(TestStringname, TestStringvalue);
// New code:
HttpResponseMessage response = await client.SendAsync(m);
if (response.IsSuccessStatusCode)
{
var x = await response.Content.ReadAsStringAsync();
}
}
}
}
I'm not getting the expected result back, which is just "Hello World"