C# - Cannot Fire HttpListener Properly

Mar 30, 2011

I have to establish an HttpListener that will wait for requests made by our client's server. I have to receive that request on port 8088 and extract the query string. That is the easy part. I'm running the HttpListener in a windows service. I cannot get it to fire properly. I build the setup project install the service on our server and it never starts. I suspect there's an error with my code.

HttpListenerClass:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Threading;
namespace lalalolo
{
class HttpListenerClass
{
bool keepAlive = true;
public void AddToFile(string contents)
{
var fs = new FileStream(@"C:HttpListenerserv.txt", FileMode.OpenOrCreate, FileAccess.Write);
var sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.WriteLine(contents);
sw.Flush();
sw.Close();
}
private HttpListener listener;
public HttpListenerClass()
{
ThreadPool.SetMaxThreads(50, 100);
ThreadPool.SetMinThreads(50, 50);
listener = new HttpListener();
listener.Prefixes.Add("http://*:8088/");
}
public void Start()
{
listener.Start();
if(keepalive == true){
{
try
{
HttpListenerContext ctx = listener.GetContext();
ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessRequest), ctx);
}
catch(Exception ex)
{
AddToFile(ex.Message);
}
}
}
}
public void Stop()
{
listener.Stop();
keepalive == false;
}
public void ProcessRequest(object listenerContext)
{
try
{
var context = (HttpListenerContext)listenerContext;
string QS = context.Request.QueryString["ID"];
AddToFile(QS);
}
catch(Exception ex)
{
AddToFile(ex.Message);
}
}
}
}
Service1.cs:
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.ServiceProcess;
using System.Text;
using System.Threading;
namespace lalalolo
{
public partial class HttpListenerTest1 : ServiceBase
{
HttpListenerClass HTTP = new HttpListenerClass();
public void AddToFile(string contents)
{
var fs = new FileStream(@"C:HttpListenerserv.txt", FileMode.OpenOrCreate, FileAccess.Write);
var sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.WriteLine(contents);
sw.Flush();
sw.Close();
}
public HttpListenerTest1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
HTTP.Start();
}
protected override void OnStop()
{
HTTP.Stop();
}
}
}

View 1 Replies


Similar Messages:

Is Default Value Necessary For The Validation To Fire Properly On Custom Config Section's Properties

Jul 26, 2010

i have the following property which takes an IP address as its value and defined in my custom config section as follows and To validate the IP address i am using a Reg expression.

[ConfigurationProperty("SMTPServer", IsRequired = true, DefaultValue = "0.0.0.0")

View 1 Replies

Web Forms :: How And Where To Use The Httplistener

Sep 5, 2010

I'm having some problems using the httplistener. Basically what I want to do is have my localhost running on [URL]. Under default.aspx.cs I want a listener waiting for the page to get a request. The webpage is then called by for example a console application doing a request to [URL] The problem I'm expering is that I have this code on the localhost running in page load for the page. I realize now that this will just keep my localhost waiting for a reply

[Code]....

This code is run from a console application

[Code]....

Then when I run my console application with this code, I get an error indication the connection had to be forcibly closed. What I'm guessing is that the IIS collides with the listener. Im wondering how and where do I set up a httplistener in a web page?? Is a httplistener neccesary for IIS, or is httplistener used instead of a IIS?? I can't change any port because localhost can only use one at a time? I cant use requeststring because the amount of data I need to send surpass the limit of requeststring.

View 3 Replies

Web Forms :: How To Set Up A HttpListener

Mar 18, 2011

I am instructed to use an HttpListener. A Service will call my URL, for example: [URL] My question is this. What kind of file do I use for a listener. Is it an .aspx file together with its .cs file as usual? If that is the case, I am told to retreive a string in this function below. I wonder how I will set this up in this function below correctly in order for "listen" for this String. I need to see that ipnValid == true. Do I do this in the Page_Load in any way etc.. ? (I beleive the String that is listening for is parsed with request.Form.Keys)

[Code]....

View 7 Replies

C# - HttpListener Windows Service Vs HttpHandler .aspx Dilemma

Mar 31, 2011

In a Windows Service I implemented an HttpListener that will handle incoming HTTP Requests to a certain port, parse the query string, insert it in database and send a confirmation response. However, the clients said that they were a bit skeptical and asked if the same could have been done via a webpage. Like having an HTTPHandler listen to a certain port. Got me thinking. What would you do in my situation? Go with the HttpListener/Windows Service or HTTPHandler/.aspx?

View 2 Replies

ADO.NET :: How To Get Working Properly In EF 4.0

Aug 26, 2010

I am trying to create an Abstract class that looks like the following (note that I coded it right inline here so it may not compile):

[Code]....

I want to (in my edmx design) be able to inherit from EntityBase and have each of those 6 columns be added to the physical database table representing the object that inherits it. So, for example, I have a class called Test that would look like this:

[Code]....

That Test class should have its physical data store mapping based on the other "stuff" plus the properties inherited from EntityBase. Thus, the database table for Test needs to also include those 6 columns from EntityBase. However, I'd like for it to be set up in a way so that they get mapped such that in the edmx design (what is that designer called anyway) when an entity inherits from the EntityBase, I don't need to do any further work to propogate those 6 columns over to the underlying database table. Am I making sense in how I am explaining this? how to accomplish this?

On a side note (and this can be answered separately or not at all) assuming this mapping is in place, NHibernate has a concept called an Interceptor. I'd like to add an "interceptor" to the delete function of any entity that is inherited from EntityBase so that it updates DeletedAt with the current time and DeletedBy with the current user and the same would be true for any updates with UpdatedAt/By. With NHibernate, you can test inside of this interceptor whether or not the object is of a certain type (e.g. object is EntityBase). Any ideas on how to get this with EF 4.0?

View 1 Replies

C# - How To Set Webservice URL Properly

Oct 1, 2010

I have a ASP.NET application. Inside the asp.net application I have a folder called WebServices where I keep all the .asmx files.

I am referring these asmx files inside asp.net .cs files. Instead of giving the full url to the webservice.url property how can i set the path like this.

ds.Url = this.ResolveUrl("~/WebServices/xxx.asmx");

View 2 Replies

Properly Deploy To IIS 7?

Jan 4, 2011

I deploy the project to our production server using Visual Studio 10's ftp uploader. It's very slow and I notice it doesn't remove deleted files (ie files deleted in the project) from the server once finished.

How can I make this step more robust, automated and professional?

View 1 Replies

MVC :: CSS Not Loading Properly?

Oct 20, 2010

Css file is on the Root in the Content/CSS/Site.css folder. Now I am using T4MVC.tt for strongly typed names like

<link href="<%: Links.Content.CSS.Site_css %>" rel="stylesheet" type="text/css" />

Page is not rendering CSS at all. But if I remove "" on href like

<link href=<%: Links.Content.CSS.Site_css %> rel="stylesheet" type="text/css" />

everything is working fine but I don't get any Intelli for T4MVC which I don't want.

View 4 Replies

Can't Get Bat File To Run Properly

Feb 3, 2012

I've got a web service that creates a .BAT file - that batch file does this

Code:
set path=D:
eporting
amc rpt/printers

This runs an app in that folder called AMC.exe

It's supposed to create an AMC.log file - it does not.

But when I run that .BAT file from windows itself it does create the AMC.log file..

View 2 Replies

How To Properly Add A Namespace To Project

Apr 2, 2010

Just using the class designer, now whenever I add a class through the class designer and double click it there is no namespace there. If I specify the namespace in the class code, when I go back into the class diagram the class disappears. Is there something I am doing wrong fellows ?

View 2 Replies

C# - GridView Isn't Updating Properly

Sep 14, 2010

I have a Gridview with these parameters:

<asp:GridView runat="server" ID="ItemGrid" CssClass="Grid"
AutoGenerateColumns="false"
AutoGenerateDeleteButton="true" OnRowDeleting="RowDeleting"
AutoGenerateEditButton="true" onRowEditing="RowEdit"
OnRowCancelingEdit="CancelRowEdit" onRowUpdating="RowUpdating"
DataKeyNames="Item_ID">
<Columns>
<asp:BoundField HeaderText="Item" DataField="Item"/>
<asp:BoundField HeaderText="Family" DataField="Family"/>
<asp:BoundField HeaderText="Structure" DataField="Structure"/>
<asp:BoundField HeaderText="Updated" ReadOnly="true" DataFormatString="{0:d}" DataField="Updated"/>
</Columns>
</asp:GridView>


On updating it calls:

protected void RowUpdating(object sender, GridViewUpdateEventArgs e){
int Item_ID = (int)this.ItemGrid.DataKeys[e.RowIndex][0];[code]...

It generates the Update/Edit/Delete buttons, my Delete function is working exactly how I want and the 'Edit' button generates editable TextBoxes as it should.

My problem is in the updating part, the strings Item, Family, Structure are getting the old values, not the new values I put in the generated text boxes.If I hard code in values they are updated to the database and the DateTime.Now is always updating correctly in the database so the update query is working.

I've been looking at this/reading forums testing things for a couple days now. I'm sure I'm just missing something simple that I have overlooked.

Edit:It has been answered but for those who were curious this is my dataBind();

protected void dataBind()
{
ItemTableAdapter taItem = new ItemTableAdapter();
this.ItemGrid.DataSource = taItem.GetActive();
this.ItemGrid.DataBind();
}

View 3 Replies

Convert String To Int In C# Properly

Jun 13, 2010

I cannot get textbox value to int. like that;

int muvalue = Textbox1.Text;

it doesn't work.

View 5 Replies

ADO.NET :: Properly Closing Connection To SQL

Jan 17, 2011

I'm trying to make sure a block of code behind properly closes a connection to SQL after it's finished. But when I add the line "cmd.Connection.Close();" Visual Studio underlines "cmd" in green and says "unreachable code detected" What does that mean and how do I correct it?

[Code]....

View 4 Replies

CustomError Not Working Properly

Apr 20, 2010

I am using following setting for customError.

< customErrors mode="On" defaultRedirect="GenericErrorPage.aspx" >
< error statusCode="403" redirect="NoAccess.aspx" />
< error statusCode="404" redirect="FileNotFound.aspx" />
< /customErrors>

I have a folder "Admin" having access to administrators role. When someone other than administrators tries to access the pages inside admin folder, it is redirected to login page. My expectation is to display "NoAccess.aspx". Whats wrong with this code? Or is there other meaning to statusCode=403.

View 1 Replies

Use A Concatenation Of 2 Columns In A SQL DB Properly?

May 28, 2010

I'm using LinqToSql like this with a CheckBoxList in ASP.NET:

var teachers = from x in dc.teachers select x;
cbl.DataSource = teachers;
cbl.DataTextField = "name";
cbl.DataValueField = "teacherID";
cbl.DataBind();

I want to display both "firstname" and "name" in the DataTextField however. I found this solution but I'm using LINQ: [URL]

View 3 Replies

C# - How To Properly Populate DataSet Twice

Dec 7, 2010

I've got a SqlConnection with a sqlquery that may not bring any results. On the rare occasion this happens, I have another sqlquery and another connection to the database. There has to be a better way to do this, no?

On a side note, is this best to close the connection after .Fill? I assume so, but haven't seen it used anywhere.

SqlConnection dbSqlConnection = new SqlConnection(--);
SqlDataAdapter dbSqlDataAdapter = new SqlDataAdapter(sqlquery, dbSqlConnection);
DataSet dbDataSet = new DataSet();
dbSqlDataAdapter.Fill(dbDataSet, "popGrid");
dbSqlConnection.Close();
if (dbDataSet.Tables["popGrid"].Rows.Count == 0)
{
SqlDataAdapter newSqlDataAdapter = new SqlDataAdapter(sqlquery2, dbSqlConnection);
newSqlDataAdapter.Fill(dbDataSet, "popGrid");
dbSqlConnection.Close();

View 2 Replies

C# - Properly Set Up Silverlight App For Debugging

Jun 24, 2010

First of all, this is my first attempt at a silverlight app and it's a prototype. I have a pre-existing solution with multiple projects. One of those projects is a web portal that has a services directory and publish a .asmx. I added the silverlight app to my solution.When I run the silverlight prototype, it gives me the message: "The silverlight project you are about to debug uses web services. Calls to the web service will fail unless the silverlight project is hosted in and launched from the same web project that contains the web service." That's fine. How do I do that? When I run the silverlight app directly, it runs in the browser as

"C://file/.../PrototypeTestPage.html"

I tried taking that HTML file and adding it to my portal and then navigating to the HTML file. That just gives me a blank page. After the page loads, the browser shows a "Waiting for localhost..." as if it's making the service calls, but my breakpoints on the service calls aren't being called. Can someone give me some pointers?

View 1 Replies

Grid Is Not Getting Bound Properly In IE?

Nov 9, 2010

My grid is not binding properly in IE and I found the reason why it is not working. one of my column value in grid is showing video and database value is

<object id='video' width='462' height='407' type='application/x-shockwave-flash'
data='http://view.vzaar.com/286291.flashplayer'>
<param name='movie' value='http://view.vzaar.com/286291.flashplayer'>
<param name='allowScriptAccess' value='always'>
<param name='allowFullScreen' value='true'>
<param name='wmode' value='transparent'>
<param name='flashvars' value='colourSet=blue&brandText=LSAT+Freedom&brandLink=lsatfreedom.com'>
<embed src='http://view.vzaar.com/286291.flashplayer'></embed>
</object>

When I comment to this column while binding, my grid is working fine and showing all next records.
But I want this column.

How to bind <object ....> tag to grid so that a video can be displayed.

View 1 Replies

How To Config KIGG To Run Properly

Feb 17, 2010

I'm very new for ASP.NET MVC. I found that this is very cool thing and KIGG is good to start creating real MVC web application.

I've followed KIGG development guide part 1 and run application.

However, only listing directory shows on web browser as below

Directory Listing -- /
Friday, February 05, 2010 12:44 PM <dir> ActionResult
Friday, February 05, 2010 12:44 PM <dir> App_Data
Friday, February 05, 2010 12:44 PM <dir> Assets
Friday, February 05, 2010 01:08 PM <dir> bin
Friday, February 05, 2010 12:44 PM <dir> BootstrapperTasks
Friday, February 05, 2010 12:44 PM <dir> Controllers
Friday, February 05, 2010 12:44 PM <dir> Controls
Friday, February 05, 2010 12:44 PM <dir> DataServices
Friday, February 05, 2010 12:44 PM <dir> ErrorPages
Friday, February 05, 2010 12:44 PM <dir> Extension
Friday, February 05, 2010 12:44 PM <dir> Filters
Friday, February 05, 2010 12:44 PM <dir> Handlers
Friday, February 05, 2010 12:44 PM <dir> Helpers
Monday, February 15, 2010 08:33 AM <dir> Logs
Friday, February 05, 2010 12:44 PM <dir> MailTemplates
Friday, February 05, 2010 12:44 PM <dir> Modules
Friday, February 05, 2010 12:45 PM <dir> obj
Friday, February 05, 2010 12:44 PM <dir> Properties
Friday, February 05, 2010 12:44 PM <dir> ViewData
Friday, February 05, 2010 12:44 PM <dir> Views
Sunday, August 16, 2009 12:53 PM 103 Global.asax
Sunday, August 16, 2009 12:53 PM 601 Global.asax.cs
Sunday, August 16, 2009 12:53 PM 27,779 Kigg.Web.csproj
Friday, February 05, 2010 01:35 PM 1,532 Kigg.Web.csproj.user
Sunday, August 16, 2009 12:53 PM 170 robots.txt
Monday, February 15, 2010 08:54 AM 100,524 Web.config

Version Information: ASP.NET Development Server 9.0.0.0

View 1 Replies

.net - Can't Get FormsAuthentication To Properly Work With WCF?

Apr 15, 2010

I have both the wcf and asp.net project together in the same project. (I'm running on Azure, so this is more convenient).I have this set in the web.config:

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
y wcf service is decorated with:
[code]...

View 1 Replies

Asp.net - 3D To Get The System To 'flow' Properly

Jan 25, 2010

I'm integrating a number of e-comm sites into different banks and decided the easiest method was to add in the dotnetcharge (www.dotnetcharge.com) library.It works well and means I can keep much of my code the same for each bank type and transaction.However, their support is a bit sucky (4 emails sent, 1 reply) and I'm utterly baffled on the 3D Secure issue.Does anyone have experience with dotnetcharge and 3D Secure?I have set the MerchantURL and the actual 3D Secure screen comes up - but I'm unsure how to get the system to 'flow' properly.Does anyone have any code examples or even pointers in the right direction?Failing that.This particular integration is with SagePay,which also has God-awful documentation and support.
Code for reference is as follows;

[code]...

View 2 Replies

VB.Net Data Report Not Working Properly

Feb 16, 2011

I have develoed a vb.net application for my client. I have been using datareport for that. The Data report get the output from the dataset file with the parameter. Now we need to show the value order by. For this i have added the order by in sql query which is generated by .xsd file. But still the output does like,...................

View 1 Replies

Page Is Displaying Properly In IE But Not In Mozilla?

Dec 27, 2010

I am working asp.net 3.5. My page is displaying properly in IE but not in mozilla. See The image. I am hiding or showing Reject/ Reschedule : option on click event.

<tr>
<td align="right" style="padding-top: 4px" id="trRejResch" runat="server">
Reject/ Reschedule :
</td>
<td align="left" style="height: 25px;" id="trRejResch1" runat="server">
<telerik:RadComboBox OnClientKeyPressing="onKeyPressing" ID="txtRejResch" MarkFirstMatch="true"
runat="server" Width="157px" Height="60px" CollapseDelay="0" CollapseAnimation-Duration="0"
DataSourceID="sqlDSRejResch" DropDownWidth="154px" AllowCustomText="true" DataTextField="nTypeDesc">
</telerik:RadComboBox>
<asp:SqlDataSource ID="sqlDSRejResch" runat="server" ConnectionString="<%$ ConnectionStrings:SqlConnectionString %>"
SelectCommand="select nTypeDesc from NoteType where nType in (2,3)" />
</td>
</tr>

View 1 Replies

MVC :: Additional Route Not Working Properly

Feb 15, 2010

I have added a new route to Global.asax in order for me to create some nice seo friendly URLs for some news items I am displaying

routes.MapRoute(
"News",
// Route name
"{controller}/{action}/{id}/{title}",
// URL with parameters
new { controller =
"News", action =
"Story", id =
"", title =
"" }
// Parameter defaults );
routes.MapRoute{"Default",
// Route name
"{controller}/{action}/{id}",
// URL with parameters
new { controller =
"Home", action =
"Index", id =
"" }
// Parameter defaults );

The problem I have is that when I now hit my home page I am getting [URL] displayed in my URL rather [URL] which is what I used to get. I think the news route is picking up everything. Has anyone any ideas on what constraint I could put on the news route above so that it only ever processes requests from the news route. I was thinking of doing a reg ex on the title and excluding anything with the '-' character in it but I coud not get that to work

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved