Error: Attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. I resolved this issue by placing "ClientAccessPolicy.xml" into Web service location "C:/inetpup/MyService" folder. Go ahead and create one "ClientAccessPolicy.xml" file with following content and save into your service location folder in "C:/inetpup/ <?xml version="1.0" encoding="utf-8"?> <access-policy> <cross-domain-access> <policy> <allow-from http-request-headers="SOAPAction"> <domain uri="*"/> </allow-from> <grant-to> <resource path="/" include-subpaths="true" /> </grant-to> </policy> </cross-domain-access> </access-policy> In some cases you may have place one more file "crossdomain.xml" <?xml version="1.0"?> <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"> <cross-domain-policy> <allow-http-request-headers-from domain="*" headers="*"/> </cross-domain-policy> |
Thursday, January 06, 2011
Attempting to access a service in a cross-domain way without a proper cross-domain policy in place......
Monday, January 03, 2011
CS0135: 'Model' conflicts with the declaration 'System.Web.Mvc.ViewPage.Model'
CS0135: 'Model' conflicts with the declarationSystem.Web.Mvc.ViewPage<TModel>.Model After spending couple of hours I found the solution, before my try I tried all the option suggested on internet like: add the namespace with the class which you are using Inherits="System.Web.Mvc.ViewPage<Attachment>" and add a <%@ Import namespace="MyProject.Models" %> Or Inherits="System.Web.Mvc.ViewPage< MyProject.Models.Attachment>" But for me problem was different, the problem was Cause I used validation control (ValidationMessageFor) to and passed wrong parameter with "=>" expression like: Line -1: <%= Html.ValidationMessageFor(Model => Model.Employee)%></div> Line -2: <% Html.RenderPartial("Attachment", Model ); %> Because of Line -1: mistake Line -2: was giving error "CS0135: 'Model' conflicts with the declaration 'System.Web.Mvc.ViewPage<TModel>.Model" Solution I correct above line like below <%= Html.ValidationMessageFor(Employee=> Model.Employee)%></div> <% Html.RenderPartial("Attachment", Model ); %> It was very stupid mistake but its took longer time to analyzed, Now my page is working fine. |
Saturday, January 01, 2011
ASP.NET MVC 2 common problems while develope a View
ASP.NET MVC 2 common problems and solutions While working with MVC2 with ASP.Net, I faced couples of problem while developing the View form, some of those are below 1) Multiple submit button on the same page 2) How to make Default Button 3) How to add Image on the Submit Button 4) Validation Control on ASP.Net MVC 2 5) How to add Image with the validation message After spending couple of hours I got good links where you get all these solution How to put multiple submit button on the same page When you have one web page having couples of action then you need multiple buttons on the same page and each button has different ResultAction, Find solution here How to make Default Button in ASP.Net MVC View When you have multiple button and out of that you want to make one button as default, Find solution here How Image button works like page Submit button in ASP.Net MVC View When you have a requirement to put Image on the page submit button and have multiple submit button on same page. The main problem is Image button will not work like Submit button then how to put image on the submit button. I tied following solution and it works for me , Find solution here Validation Control on ASP.Net MVC 2 When you have to implements validation control in your ASP.Net MVC 2 web form then I found very good article about this, How to use validation control in ASP.Net MVC 2, Find Solution here Add image with validation message You have validation message and with the validation message your requirement to add Image (like: alert, explanation image etc.), then you can find the solution from here |
Thursday, December 30, 2010
WCF Errors with IIS7 with .Net Framework 4.0
WCF Errors with IIS7 with .Net Framework 4.0 When I start hosting WCF service on the IIS7 then I got following errors and I spend enough time to resolve this, following error could be caused by different reason but I described the reason and solution which I faced. I was using Visual Studio 2010 with .Net framework 4.0 and IIS7. Error-1: HTTP Error 404.17 - Not Found The requested content appears to be script and will not be served by the static file handler. Cause WCF service developed on different .NET framework (V4.0) and Application Pool set in different version (V2.0). Solution Go to the IIS 7 and select Application Pools à right click on your application and change the .NET Framework version to V4.0. (Change the v2.0 to v4.0 in Application Pool) Error-2: HTTP Error 500.19 - Internal Server ErrorThe requested page cannot be accessed because the related configuration data for the page is invalid.Cause This error occurs when you application deployed on the different version of .NET and Web.config has different version mentioned. Like: Application Pool running on .Net 4.0 and Web.Config includes .Net 3.5 Solution Go to the application project à right click and go to "Property Pages"à Build tab and Set the application Target Framework to .Net Framework 4.0. Another quick fix, change application pool set to 2.0 as default. Error-3: No protocol binding matches the given address 'http://localhost/IISHostedService/MyService.svc'. Protocol bindings are configured at the Site level in IIS or WAS configuration. <endpoint address="http://localhost/IISHostedService/MyService.svc" binding="wsHttpBinding" contract="IMyService"> Solution Remove this address URL from Web.config, because this is already configured in IIS. Go to the web.config and change in the Services section like below <endpoint address="" binding="wsHttpBinding" contract="IMyService"> Error-4: Metadata publishing for this service is currently disabled. There are couples of help available on internet and on the site page where this error displays. But for that was not the problem Cause Normally this error occurs when "httpGetEnabled" is false in Web.config check your web.config <serviceMetadata httpGetEnabled="true"> But for me the problem was, I created one folder explicitly in “C:/inetpub” called ‘MyFolder’ and then from the visual studio I created WCF service on that folder choosing Web location: File System and File created on “C:/inetpub/MyFolder”. Now when I deploy my WCF service and try to access then its throws following error “ Metadata publishing for this service is currently disabled.” Solution DONOT create any folder explicitly on “C:/inetpub” and while creating new WCF service choose following option Web location: HTTP and File created on “http://localhost/MyFolder”. |
Wednesday, October 13, 2010
How to pass Credential to Web Service with Basic Authentication
Friday, October 01, 2010
Table Value Parameter with LINQ, (LINQ for Stored Procedure that has datatable as an input parameter)
Table Value Parameter with LINQ, (LINQ for Stored Procedure that has datatable as an input parameter) If you are using LINQ to SQL with SQL server database then Visual Studio will not allow you to drag your SP into dbml file like you do for other simple SP and also Visual Studio will not able to generate the code for this. There is no other ways to generate the code for this situation (SP has input parameter as a datatable) in the DataContext. You have to write the code into partial class (given with your .dbml file), now assume you have SP signature like below Stored Procedure CREATE PROCEDURE [dbo].[GetResource] ( @ResourceID dbo.Resource READONLY) Resource: is datatable type CREATE TYPE [dbo].[Resource] AS TABLE ( [ResourceId] [int] NOT NULL ) While writing the code in the DataContext we have to manually execute the SP and return as a List, see below code NameSpace using System.Data.Linq; using System.Data.Linq.Mapping; using System.Linq; using System.Linq.Expressions; DataContext Code public partial class YourDataContext : System.Data.Linq.DataContext { public IEnumerable<ResourceData> GetResource(List<int> resourceId) { DataTable resourceIdTable = new DataTable(); resourceIdTable.Columns.Add("Resource", typeof(int)); // Fill the datatable from the input List foreach (int r in resourceId) resourceIdTable.Rows.Add(r); // "GetSqlCommand()" is a method will open the connection and return sqlCommand Object SqlCommand cmd = ConnectionManager.GetSqlCommand("GetResource", connectionString); cmd.CommandType = CommandType.StoredProcedure; SqlParameter p1 = cmd.Parameters.AddWithValue("@ResourceID", resourceIdTable); p1.SqlDbType = SqlDbType.Structured; p1.TypeName = "Resource"; SqlDataReader reader = cmd.ExecuteReader(); return this.Translate<ResourceData>(reader).ToList(); } } Call DataContext Method YourDataContext rdc = new YourDataContext(); IEnumerable<ResourceData> result = rdc.GetResource(resourceId); foreach (ResourceData res in result) { MessageBox.Show("ResourceId : " + res.Id + " Resource Name : " + res.Name); } ResourceData: is Entity class like below public sealed class ResourceData { private int _id; private string _name; public int Id { get { return _id; } private set { _id = value; } } public string Name { get { return _name; } private set { _name = value; } } } |
LINQ for Stored procedure returning Multiple ResultSets
LINQ for Stored procedure returning Multiple ResultSets When you have SP which is returning multiple recordset and when you try to drag into dbml file then Visual Studio will not able to generate the code for this in the DataContext class. For this you have to manually write the code into Partial class (present with the dbml file), I usually drag my SP into dbml file and then copy past generated code into partial class and modify, just replace "ISingleResult" with "IMultipleResults". Let say you have one SP called "GerResources" which is returning two RecordSets Stored Procedure CREATE PROCEDURE [dbo].[GetResource] ( @ResourceID int ) AS Begin Select Id, Value from Employee where ResourceId = @ResourceID Select Name , Value from Content where ResourceId = @ResourceID End NameSpace using System.Data.Linq; using System.Data.Linq.Mapping; using System.Linq; using System.Linq.Expressions; DataContext Code public partial class YourDataContext : System.Data.Linq.DataContext { [FunctionAttribute(Name = "dbo.GetResource")] [ResultType(typeof(Employee))] [ResultType(typeof(Content))] public IMultipleResults GetResource(int resourceID) { IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), resourceID); return ((IMultipleResults)(result.ReturnValue)); } } Content and Employee is Entity class. public sealed class Employee { private int _id; private string _value; { get { return _id; } private set { _id = value; } } { get { return _value; } private set { _value = value; } } } public sealed class Content { private int _name; private string _value; { get { return _name; } private set { _name = value; } } { get { return _value; } private set { _value = value; } } } Call DataContext Method // Create and open the connection YourDataContext rdc = new YourDataContext(); List<Employee> emp = result.GetResult<Employee>().ToList(); List<Content> cont = result.GetResult<Content>().ToList(); foreach (Employee e in emp) { MessageBox.Show(e.Id + e.Value); } foreach (Content c in cont) { MessageBox.Show(c.Name + c.Value); } Note: If you have single Row returning from SP then use "Single()" method instead of "foreach" loop //Create and open the connection YourDataContext rdc = new YourDataContext(); List<Employee> emp = result.GetResult<Employee>().Single(); //Display the value MessageBox.Show(e.Id + e.Value); |