System.Net.Sockets.SocketException: A system call has failed - asp.net

I have the following code snippet that run with IIS Express of VS2012. It is able to send out email and working fine with smtp server.
Then deployed it as New Application on IIS 7. When I run it, I am getting the error “System.Net.Sockets.SocketException: A system call has failed 11.29.83.49:25” .
Do you have any idea what causing the error?
Do I miss something to configure IIS server to work with smtp server?
protected void Page_Load(object sender, EventArgs e)
{
System.Net.Mail.MailMessage _message = new System.Net.Mail.MailMessage();
_message.Subject = "Hi Testing";
_message.SubjectEncoding = System.Text.Encoding.UTF8;
_message.From = new System.Net.Mail.MailAddress("sender#gmail.com","Test");
_message.To.Add(new System.Net.Mail.MailAddress("receiver#gmail.com", "Test"));
System.Net.Mail.AlternateView _content_view = System.Net.Mail.AlternateView.CreateAlternateViewFromString("Message Body");
_message.AlternateViews.Add(_content_view);
sendEmailMessage(_message);
}
public void sendEmailMessage(System.Net.Mail.MailMessage message)
{
getClientFromConfig().Send(message);
}
private static System.Net.Mail.SmtpClient getClientFromConfig()
{
System.Net.Mail.SmtpClient _client = new System.Net.Mail.SmtpClient();
_client.Host = "host name/ip here";
_client.Port = 25;
return _client;
}
Could anyone please suggest to get it work?

I think the reason is firewall.
Open IIS Manager ->Application Pool and select your pool then click advanced settings.
Change your Identity as
Network Service
-below the process model

Related

Windows phone app crashes while communicating to wcf service without internet connection

I have added the web service to my WPF windows phone store app, when i run my app in emulator it works, but sometime it get creshes cause lack of internet connectivity.
i'm checking my emulator IMEI is registerd or not in database using WCF service on main_pageload event
my code looks like this
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
SchoolWebService.SchoolAppWebServiceSoapClient proxy = new SchoolAppWebServiceSoapClient();
proxy.CheckIMEIRegisteredOrNotCompleted += new EventHandler<CheckIMEIRegisteredOrNotCompletedEventArgs>(proxy_CheckIMEIRegisteredOrNotCompleted);
proxy.CheckIMEIRegisteredOrNotAsync(strIMEI);
}
in this service im checking the mobile IMEI registerd or not. i have checked by debugging the app it goes upto proxy.CheckIMEIRegisteredOrNotAsync(strIMEI);
when it leave the context it throuw the error
An exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.ni.dll but was not handled in user code
please suggest me some advice,,,thanks in advance
To check if the Internet connection is available I just simply create a method to check it and execute it then application is launching or page is loading. This method I create in App.xaml.cs:
public bool CheckInternetConnection()
{
bool connection = true;
ConnectionProfile currentConnection = NetworkInformation.GetInternetConnectionProfile();
if (currentConnection == null)
{
connection = false;
}
return connection;
}
Then in some page_loaded event I execute it:
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
bool connection = ((App)Application.Current).CheckInternetConnection();
if (connection == false)
{
MessageBox.Show("Internet connection is not available", "Internet connection", MessageBoxButton.OK);
Application.Current.Terminate();
}
}
Now then a client don't have the Internet connection available it won't crash, but it will show a message for the user. I hope it will help.

how to link to ssrs report from asp.net webpage

I'm having trouble linking to an ssrs report from my asp.net webpage.
the direct link is
server/Reports/Pages/Report.aspx?ItemPath=%2fRig+Dashboard%2fRig+Status+Report
I also need to pass in two parameters which is FileTypeID and Date
Please help...
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://server/Reports"); // Report Server URL
ReportViewer1.ServerReport.ReportPath = "/Rig Dashboard/Rig Status Report"; // Report Name
ReportViewer1.ShowParameterPrompts = false;
ReportViewer1.ShowPrintButton = true;
ReportViewer1.ServerReport.Refresh();
The attempt to connect to the report server failed. Check your connection information and that the report server is a compatible version.
The request failed with HTTP status 404: Not Found.
Your doing it wrong. You are trying to call the 'landing page' : /Reports NOT THE SERVICE: /ReportServer. Yuriy gave you a good place to get started. I can give you an example of how I do it in some local code I use in WPF calling a Windows Form(blech!):
private void ResetReportViewer(ProcessingMode mode)
{
this.reportViewer.Clear();
this.reportViewer.LocalReport.DataSources.Clear();
this.reportViewer.ProcessingMode = mode;
}
private void ReportViewerRemote_Load(object sender, EventArgs e)
{
ResetReportViewer(ProcessingMode.Remote);
reportViewer.ServerReport.ReportServerUrl = new Uri(#"http://server/ReportServer");
reportViewer.ServerReport.ReportPath = "/Folder/ReportName";
reportViewer.RefreshReport();
}
private void ReportViewerRemoteWithCred_Load(object sender, EventArgs e)
{
ResetReportViewer(ProcessingMode.Remote);
reportViewer.ServerReport.ReportServerUrl = new Uri(#"http://server/ReportServer");
reportViewer.ServerReport.ReportPath = "/Folder/ReportName";
DataSourceCredentials dsCrendtials = new DataSourceCredentials();
dsCrendtials.Name = "DataSource1";
dsCrendtials.UserId = "DedicatedUser";
dsCrendtials.Password = "P#ssword(jk)";
reportViewer.ServerReport.SetDataSourceCredentials(new DataSourceCredentials[] { dsCrendtials });
reportViewer.RefreshReport();
}

CRM 2011 Online via an ASP.net application does not work, same code via Console Application Works -> "Authentication Failure"-error

I'm trying to connect to a CRM 2011 Online environment. I'm able to connect via a "Console Application", but when I'm trying to connect via an "ASP.net"-application with the same code, it doesn't work, it gives me the "Authentication Failure"-error ({"An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail."}).
Is there something special we need to do to make it work on an "ASP.net" environment. I tested out several solutions I found on the internet, but all gives me the same error.
A "code"-snippet of my simplified code:
private static ClientCredentials GetDeviceCredentials()
{
return Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice();
}
protected void Button1_Click(object sender, EventArgs e)
{
//Authenticate using credentials of the logged in user;
string UserName = "*****"; //your Windows Live ID
string Password = "*****"; // your password
ClientCredentials Credentials = new ClientCredentials();
Credentials.UserName.UserName = UserName;
Credentials.UserName.Password = Password;
Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
//This URL needs to be updated to match the servername and Organization for the environment.
Uri OrganizationUri = new Uri("https://*****.crm4.dynamics.com/XRMServices/2011/Organization.svc"); //this URL could copy from Setting --> Developer Source
Uri HomeRealmUri = null;
//OrganizationServiceProxy serviceProxy;
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, GetDeviceCredentials()))
{
IOrganizationService service = (IOrganizationService)serviceProxy;
OrganizationServiceContext orgContext = new OrganizationServiceContext(service);
var theAccounts = orgContext.CreateQuery<Account>().Take(1).ToList();
Response.Write(theAccounts.First().Name);
}
}
I tried several things, like deleting the content of "LiveDeviceID"-folder an re-running the device registration tool. but is weird that it works in the "console application" but not on my "asp.net"-solution...
PS : I am able to generate the "context"-file via crmsvcutil.exe /url:https://org.crm4.dynamics.com/XRMServices/2011/Organization.svc /o:crm.cs /u:username /p:password /di:deviceUserName /dp:devicPWD
Is there any particular reason you have
Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
You shouldn't need that line for windows live authentication.
Even with that the code seems valid so it is something to do with the Device Registration. I suggest rather than just call it directly like you have
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, GetDeviceCredentials()))
{
You try something like the following because you only need to register once:
ClientCredentials deviceCredentials;
if ((CRMSettings.Default.DeviceID == String.Empty) || (CRMSettings.Default.DevicePassword == String.Empty))
{
deviceCredentials = Microsoft.Crm.Services.Utility.DeviceIdManager.RegisterDevice();
}
else
{
deviceCredentials = new ClientCredentials();
deviceCredentials.UserName.UserName = CRMSettings.Default.DeviceID;
deviceCredentials.UserName.Password = CRMSettings.Default.DevicePassword;
}
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, deviceCredentials))
{
I have had issues in the past where I get an "already registered" response from the RegisterDevice call.
I would also dump out the Device ID and Password so you can see if they are being set.

Crystal Report 2011 Login prompt in asp.net

We are using Crystal Reports 2011 & SQL Server 2008 (Windows 7 64 bit). Whenever I try to deploy the crystal reports in the IIS it is always prompting enter the database login information. I have tried the below options
Set the login information in the code
Set IIS app pool to LocalService
Nothing works. Here is the code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ConfigureCrystalReports();
}
else
{
ReportDocument doc = Session["Report"] as ReportDocument;
SetLogon(doc);
CrystalReportViewer1.ReportSource = doc;
CrystalReportViewer1.RefreshReport();
}
}
private void ConfigureCrystalReports()
{
ReportDocument reportDoc;
if (!IsPostBack)
{
reportDoc = new ReportDocument();
reportDoc.Load(Server.MapPath("~/Sample.rpt"));
Session.Add("Report", reportDoc);
}
else
{
reportDoc = Session["Report"] as ReportDocument;
}
SetLogon(reportDoc);
CrystalReportViewer1.ReportSource = reportDoc;
CrystalReportViewer1.RefreshReport();
}
private void SetLogon(ReportDocument reportDoc)
{
var connectionInfo1 = new ConnectionInfo()
{
ServerName = #"ODBCDSN",
DatabaseName = "hrdw_old",
IntegratedSecurity = true
};
SetDBLogonForReport(connectionInfo1, reportDoc);
}
private void SetDBLogonForReport(ConnectionInfo connectionInfo1, ReportDocument reportDocument)
{
Tables tables = reportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo1;
tableLogonInfo.ConnectionInfo.Type = ConnectionInfoType.SQL;
table.ApplyLogOnInfo(tableLogonInfo);
}
reportDocument.SetDatabaseLogon(connectionInfo1.UserID, connectionInfo1.Password);
}
}
Steps tried in IIS:
Application pool: ASP.NET 4.0 Default app pool
Also enabled Windows Authentication in IIS & disabled anonymous authentication.
Tried anonymous authentication only.
SQL Server has both windows and sql server authentication.
I will not be able to use dataset since the crystal reports will be developed by someone using command objects. It works perfectly good in the Visual studio 2010 environment. But doesnt work in IIS.
Am I missing something basic? Any help is appreciated.
Thanks
Shankar.
Here is how this was solved. It was a bit of workaround
CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc = doc.ReportClientDocument;
CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rcd = rptClientDoc;
string server = #"<SERVER>";
string db = "<DATABASE>";
string user = "<USER>";
string pass = "PASSWORD";
rptClientDoc.DatabaseController.LogonEx(server, db, user, pass);
//Create the logon propertybag for the connection we wish to use
CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag logonDetails = new CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag();
logonDetails.Add("Auto Translate", -1);
logonDetails.Add("Connect Timeout", 15);
logonDetails.Add("Data Source", server);
logonDetails.Add("General Timeout", 0);
logonDetails.Add("Initial Catalog", db);
logonDetails.Add("Integrated Security", "false");
logonDetails.Add("Locale Identifier", 1033);
logonDetails.Add("OLE DB Services", -5);
logonDetails.Add("Provider", "SQLOLEDB");
logonDetails.Add("Use Encryption for Data", 0);
//Create the QE (query engine) propertybag with the provider details and logon property bag.
CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag QE_Details = new CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag();
QE_Details.Add("Database DLL", "crdb_ado.dll");
QE_Details.Add("QE_DatabaseName", db);
QE_Details.Add("QE_DatabaseType", "OLE DB (ADO)");
QE_Details.Add("QE_LogonProperties", logonDetails);
QE_Details.Add("QE_ServerDescription", server);
QE_Details.Add("QE_SQLDB", "True");
QE_Details.Add("SSO Enabled", "False");
CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo newConnInfo = new CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo();
CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo oldConnInfo;
CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfos oldConnInfos;
oldConnInfos = rcd.DatabaseController.GetConnectionInfos(null);
for (int I = 0; I < oldConnInfos.Count; I++)
{
oldConnInfo = oldConnInfos[I];
newConnInfo.Attributes = QE_Details;
newConnInfo.Kind = CrystalDecisions.ReportAppServer.DataDefModel.CrConnectionInfoKindEnum.crConnectionInfoKindCRQE;
try
{
rcd.DatabaseController.ReplaceConnection(oldConnInfo, newConnInfo, null, CrystalDecisions.ReportAppServer.DataDefModel.CrDBOptionsEnum.crDBOptionDoNotVerifyDB);
}
catch (Exception ex)
{
Label1.Text = ex.Message;
return;
}
}
doc.SetDatabaseLogon(user, pass);
To ensure that there is no login prompt at all at first I had to login to the controller and then set all the login credentials. Ensure that login credentials are reused during post back as well. After this is done, login using the reportdocument as well. This solves the issue of login prompt coming again and again.
Thanks
Shankar

SSRS Report Viewer: request failed with HTTP status 401

I've spent a lot time trying to figure this one out, but without luck - so I will try to post the question here.
I am running 2 ASP.NET websites on the same server. Both websites are running on IIS 7.5 + .NET 4. The sites use the SSRS Report Viewer to show reports from an another server.
We recently moved both the websites and RS to new servers (switching from RS 2005 to RS 2008 and switching from IIS 7.0 to IIS 7.5). However, after moved to the new servers, one of the websites are unable to view the reporting services, as we get the following error:
request failed with HTTP status 401
The strange thing is, that the Report Viewer is configured exactly the same way in the two websites (simply copy pasted between the two). Further, using the "working website", we are able to view the reports belonging to both websites - and using the other website, we are unable to view any of the reports.
The authorization looks like this in both cases:
Credentials:
[Serializable]
public sealed class ReportServerCreditentials : IReportServerCredentials
{
public WindowsIdentity ImpersonationUser
{
get { return null; }
}
public ICredentials NetworkCredentials
{
get
{
string userName = ConfigurationManager.AppSettings["ReportViewerUser"];
string password = ConfigurationManager.AppSettings["ReportViewerPassword"];
string domain = ConfigurationManager.AppSettings["ReportViewerDomain"];
return new NetworkCredential(userName, password, domain);
}
}
public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority)
{
authCookie = null;
userName = null;
password = null;
authority = null;
return false;
}
}
Report Viewer usage
public partial class ReportServicesViewer : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
if (!IsPostBack)
{
string reportingFolder = ConfigurationManager.AppSettings["ReportingFolder"];
showReport(string.Format("/{0}/{1}", reportingFolder, Request.QueryString["report"]));
}
}
private void showReport(string reportPath)
{
RevReport.ServerReport.ReportServerUrl = new Uri(ConfigurationManager.AppSettings["ReportServer"]);
RevReport.ServerReport.ReportServerCredentials = new ReportServerCreditentials();
RevReport.ServerReport.ReportPath = reportPath;
}
}
In aspx:
<rsweb:ReportViewer ID="RevReport" runat="server" Height="100%" Width="100%" Font-Names="Verdana" Font-Size="8pt" ProcessingMode="Remote" ZoomMode="Percent" ZoomPercent="100"></rsweb:ReportViewer>
Other observations
At one point, we tried to monitor the traffic between the website and RS using Fiddler, but somehow the communication actually worked in this case.
However, when I tried this at a later point, Fiddler gave the following response:
[Fiddler] The socket connection to <servername> failed. <br />ErrorCode: 10061. <br />No connection could be made because the target machine actively refused it 10.0.0.17:443
I am not sure how exactly to interpret this, as we are not using SSL for the Website <-> RS communication.
Any advice would be greatly appreciated.
I had the similar issue when we built new SSRS server. Web application was not able to connect to report server. I was able to solve the issue by doing these:
Enable Kerberos Authentication on the server
Set spn(server principal names) on the server
enable the impersonation in web application

Resources