In my console application I added a service reference to http://www.ibanbic.be/IBANBIC.asmx .
The operations in it I need to use.
Now, this is my little piece of code, and from what I saw in tutorials, this should be enough to connect to it and get a value. But the only value I get is "String is Empty".
using (BANBICSoapClient WebService = new BANBICSoapClient())
{
string bban = "*****";
try
{
string resultIban = WebService.BBANtoIBAN(bban);
if (resultIban != string.Empty)
{
Console.WriteLine(resultIban);
}
else
{
Console.WriteLine("String is empty.");
}
}
catch(Exception msg)
{
Console.WriteLine(msg);
}
}
Console.ReadLine();
Can anyone give me some more information about what is wrong?
Are you passing a valid BBAN or just the string of asterixes? Do you have a sample of valid data?
Calling the web service with data I just mocked up, e.g. (12345, *) looks to return an empty string, so that's what it might return in the event of invalid data.
Related
i'm working on a project where i am using sessions for storing message alerts. when new item is added in a database i store success message in Session["message"] and which is used to show a simple message to user. all this is working file every time new message is stored in this session. but when i moved to another page i want to destroy session and after that i want to show new page.
Function for creating sessions:-
public void Send_Response(string message, string status)
{
Session["message"] = message;
Session["status"] = status;
}
i can access this session in whole code but when i going to destroy this session it throws null reference exception.
here is the code to setting sessions to null:-
public void Set_Null_Session()
{
try
{
Response.Cookies["message"].Value = string.Empty; //not working
//Session.Abandon(); //not working
//Session.Remove("message"); //not working
//Session.Remove("status"); //not working
Session["message"] = " "; //not working
Session["status"] = " "; //not working
Session["message"] = null; //not working
Session["status"] = null; //not working
}
catch (Exception ex)
{
var error = ex.ToString();
}
}
i used Session.Remove("message") , session.Abandon() but nothing is working.
i called Set_Null_Session method in my controller before moving to another page as i want to destroy previous session.
It sounds like Set_Null_Session does not have access to the Session object. Where is that method defined? And where is it called from? You might need to pass the Session or Request object into the method.
We're creating a WPF app in which we execute python scripts from different Test Stations and show the output in its corresponding output panel, To run the scripts in parallel we are using Task but when we run the scripts in parallel from the stations, We are getting the output of other stations also into the station that is started first, we're using the following code,
private void ZmqStatusListener(string endPoint)
{
using (Context context = new Context())
{
StatusPort = string.Empty;
TestResultPort = string.Empty;
using (Socket server = context.Socket(SocketType.REP))
{
try
{
if (isStatusContextActive == false || isPortChanged == true)
{
server.Bind(endPoint);
isStatusContextActive = true;
}
}
catch (ZMQ.Exception ex)
{
if (ex.Errno != 100)
{
string IPCPort = _globalParameters.GlbParam.GlbParamIpcStartPort;
if (IPCPort == string.Empty)
{
IPCPort = "0";
}
if (endPoint == EditorConstants.PortAddress.PortPrefix + IPCPort)
{
StatusPort = endPoint;
TestReultError = EditorConstants.CommonMessageTypes.TestReultError + ex.Message + EditorConstants.CommonMessageTypes.StackTraceMessage + ex.StackTrace;
}
StopExecOfScript(default(object));
isCancelledtask = true;
ScriptStatusDesc = new ScriptStatusDesc()
{
Status = "Failed",
statusDescription = "Failed"
};
}
}
while (true)
{
string message = server.Recv(Encoding.UTF8);
UpdateTestResults(message);
server.Send(" ACK", Encoding.UTF8);
// if (message == "Test Passed")
//break;
}
}
}
}
and for testing purpose we're breaking the while loop in this code based on a test message we kept in the python script, then we are able to get the output in the respective station correctly but this way we can only run in a synchronous fashion which we don't want as we require to run the test stations in parallel and the while loop should not break as it should be listening for the response.
We were able to solve the issue by getting clues doing a sample app to reproduce the issue and to first know whether our ClrZmq pattern was correct for us or not and it is correct. The resolution we followed is that when we needed to bind that data to its corresponding View's Model object in its ViewModel so had to retrieve View's DataContext which is of Type ISomeXViewModel for the particular TestStation using an Id of that TestStation we did this cos all of our TestStations are dynamically added and we even store it to be accessed wherever necessary. This issue was caused to due multiple instances of UserControls so we explicitly needed to update the TestStation manually with a little more effort.
Sample Code Snippet
private void BindTestResult(string xmlPayLoad)
{
// converting xmlPalLoad to a class/model object
ITestStationViewModel viewModel = (ITestStationViewModel)((IView)DynamicTestStationsGrid.Children[StationNumber].Content).DataContext;
// IView class has DataContext property so I am type casting the Content which is ContentControl to IView type first and later to ITestStationViewModel
viewModel.TestStationModel = xmlPayLoadModel;
}
Thanks.
Dears,
I know that the title seems popular and easy but what I'm facing is too strange.
Simply, I have a RESTful C# .NET 4.0 web service published on the server, and I want to consume it through Java in my Android application, easy?
The problem is: whenever I call the .NET web service and get the response, java could not parse the return string into Json.
Error message:
org.json.JSONException: Value {lhs:"1 Euro",rhs: "1.3711 U.S. dollars",error: "",icc: true} of type java.lang.String cannot be converted to JSONObject
at org.json.JSON.typeMismatch(JSON.java:111)
at org.json.JSONObject.<init>(JSONObject.java:158)
at org.json.JSONObject.<init>(JSONObject.java:171)
at com.itrack21.mobileapp.LoginActivity.getUserInfo(LoginActivity.java:151)
at com.itrack21.mobileapp.LoginActivity$1$1.run(LoginActivity.java:114)
at java.lang.Thread.run(Thread.java:841)
threadid=17: thread exiting with uncaught exception (group=0x4164d700)
Java Code:
public void getRate(String link) {
try {
URL url = new URL(link);
URLConnection connection = url.openConnection();
InputStream str = connection.getInputStream();
InputStreamReader reader = new InputStreamReader(str);
BufferedReader bufReader = new BufferedReader(reader);
String line=new String();
StringBuffer buffer = new StringBuffer();
while( (line=bufReader.readLine()) != null) {
buffer.append(line);
}
JSONObject obj = null;
try {
obj = new JSONObject(buffer.toString());
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String rhs = "";
try {
rhs = obj.getString("rhs");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.i("getRate","Converted Currency = " + rhs.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Debugging:
I did many debugging scenarios but with no luck, here I will use strangest one to describe the problem.
I use my java code to consume Google web service for currency converting using the following link http://www.google.com/ig/calculator?hl=en&q=1USD=?EUR and I got the response as follows: {lhs: "1 U.S. dollar",rhs: "0.726321906 Euros",error: "",icc: true}. And here my code is working perfectly.
I copy exact Json value return from Google web service and working fine with my code, and return it as a HARD CODED String in my RESTful C# service as follows:
C# Code:
public string GetInfo()
{
return "{lhs:\"1 Euro\",rhs: \"1.3711 U.S. dollars\",error: \"\",icc: true}";
}
I request my C# .NET web service using the same code used to invoke Google web service bu I got error listed above org.json.JSONException: Value {lhs:"1 Euro",rhs: "1.3711 U.S. dollars",error: "",icc: true} of type java.lang.String cannot be converted to JSONObject at org.json.JSON.typeMismatch(JSON.java:111).
When I copy and paste the return value into my code as a HARD CODE, it works just fine.
JSONObject obj = null;
try {
obj = new JSONObject("{lhs:\"1 Euro\",rhs: \"1.3711 U.S. dollars\",error: \"\",icc: true}");
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Many "Crazy" debugging scenario done including changing the server itself, but with no luck.
What I'm doing wrong?
Regards,
In JSON, you need to wrap the keys in quotation marks too. So for this:
{lhs: "1 U.S. dollar",rhs: "0.726321906 Euros",error: "",icc: true},
you will have to do this:
{"lhs": "1 U.S. dollar","rhs": "0.726321906 Euros","error": "","icc": "true"}
You can check your JSON online at : http://jsonlint.com/
After long debugging process, I got the cause, and then the solution. Here we go:
Visit Google Maps Web Service through Chrome browser, and you will get Json response. For debugging purpose, right click on page and select View page source. Note that the string of Json is pure Json with no additions.
When you repeat same procedure with the C# .NET response through Chrome browser, you will notice that the response is NOT pure Json, it is surrounded by this: <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">{JSON String HERE}</string>.
Solution:
To remove this string surrounding the response, you have to return Json string as System.IO.Stream. Here the required code changes:
public System.IO.Stream GetInfo()
{
OutgoingWebResponseContext context = WebOperationContext.Current.OutgoingResponse;
context.ContentType = "text/plain";
return new System.IO.MemoryStream(ASCIIEncoding.Default.GetBytes("{lhs:\"1 Euro\",rhs: \"1.3711 U.S. dollars\",error: \"\",icc: true}"));
}
This solution works fine with me, but is it optimal solution? converting from object to Json, and then from Json string to bytes is little overhead, what do think? suggestions?
I am trying to get all my status messages using the following code:
public dynamic downloadStatuses(FacebookOAuthResult facebookOAuthResult, string userInput)
{
dynamic result = null;
if (facebookOAuthResult != null)
{
if (facebookOAuthResult.IsSuccess)
{
this.accessToken = facebookOAuthResult.AccessToken;
var fb = new FacebookClient(facebookOAuthResult.AccessToken);
result = fb.Get(userInput + "/statuses?format=json&limit=1500");
return result;
}
else
{
MessageBox.Show(facebookOAuthResult.ErrorDescription);
return result;
}
}
return result;
}
userInput would be my Facebook ID. Some statuses are returned but definitely does not total up to the 1500 that I have indicated. Was wondering if anyone knew how to access your first ever facebook status message or retrieve all the status message by slightly modifying the request url in the code. Is it a must to use fql?
When you query /statuses you don't get the Photo/Album/video related statuses/entries from your stream (including their comments etc). This also includes event creation and questions.
You will have to query the API with separate calls (i.e. /me/photos) to get everything. If you want to have almost the full stream of some person or page or group. Consider using FQL, querying the stream table.
EDIT : Just saw this question is probably outdated, my bad
I have following method:
public static string GetHttpHost(System.Web.HttpRequest hr)
{
return "http://" + hr.Url.Host + ":" + hr.Url.Port.ToString() ;
}
When I call this method with GetHttpHost(this.Request) and GetHttpHost(HttpContext.Current.Request), it returns different results.
For example:
My request page is http://192.168.1.103/mypage.aspx
In mypage.aspx.cs, calling GetHttpHost(this.Request) returns http://192.168.1.103:80
When rendering mypage.aspx, some biz logic is involved, so BLL.dll is loaded. In BLL.dll, calling GetHttpHost(HttpContext.Current.Request) returns http://app133:80 (app133 is our web server's name)
I searched in Stack Overflow, all related questions tell me that HttpContext.Current.Request and Page.Request are same object.
So, can anyone tell me what happened in my code?
Thanks.
No, HttpContext.Current.Request and Page.Request are not the same. Both are instances of the same class (HttpRequest) but those are different instances.
In each case, the private HttpRequest instance is created differently - I could not find the exact code creating it but keep in mind that HttpContext.Current is created only once, long before any Page.
It all boils down to the following code in HttpRequest class:
public Uri Url
{
get
{
if (this._url == null && this._wr != null)
{
string text = this.QueryStringText;
if (!string.IsNullOrEmpty(text))
{
text = "?" + HttpUtility.CollapsePercentUFromStringInternal(text, this.QueryStringEncoding);
}
if (AppSettings.UseHostHeaderForRequestUrl)
{
string knownRequestHeader = this._wr.GetKnownRequestHeader(28);
try
{
if (!string.IsNullOrEmpty(knownRequestHeader))
{
this._url = new Uri(string.Concat(new string[]
{
this._wr.GetProtocol(),
"://",
knownRequestHeader,
this.Path,
text
}));
}
}
catch (UriFormatException)
{
}
}
if (this._url == null)
{
string text2 = this._wr.GetServerName();
if (text2.IndexOf(':') >= 0 && text2[0] != '[')
{
text2 = "[" + text2 + "]";
}
this._url = new Uri(string.Concat(new string[]
{
this._wr.GetProtocol(),
"://",
text2,
":",
this._wr.GetLocalPortAsString(),
this.Path,
text
}));
}
}
return this._url;
}
}
As you can see, it first tries to read known request header (GetKnownRequestHeader method in System.Web.HttpWorkerRequest base class) and only if it fails it will invoke GetServerName method which will return either IP address or server name depending where the web application is hosted.
Didn't find any official documentation or proof as to why exactly one returns IP and other the machine name, but the above can explain the difference.