WCF服务405方法不允许例外

我正在Visual Studio 2008中编写WCF服务以托管在Windows 2008 Standard服务器上。 我在IIS7中创建了一个新的Web站点,其自己的应用程序针对ASP.NET 2.0。 我在服务器角色中添加了.NET 3.0 Frameworkfunction。 我已经完成了涉及* .svc扩展和aspnet_isapi模块的所有步骤。 我运行“ServiceModelReg -r”并重新启动IIS以及服务器本身。 我的项目针对构建的.NET framework 3.5。 我的解决方案使用到服务器Web目录的UNC路径将项目作为Web站点引用。 该项目构建没有错误,我可以在我的客户端项目(在我的Win XP开发虚拟机上)成功添加服务引用到我的WCF服务。 我的客户端项目构建并运行,但在服务方法( CheckDatabaseConnection )调用期间抛出exception。 我的web.config和服务类附在下面,后面是客户端应用程序。 我完全没有想法了! web.config中: IConnectivity.cs: [ServiceContract(Namespace=”http://validurl.net”)] public interface IConnectivity { #region Methods [WebGet()] [WebInvoke(Method=”GET”)] [OperationContract()] bool CheckDatabaseConnection(string server, string database, string user, string password); #endregion Methods } // interface IConnectivity Connectivity.svc.cs: public class […]

Enum.TryParse with Flags属性

我已经通过值或其名称为TryParse枚举编写了代码,如下所示。 如何扩展此代码以包含使用Flags属性解析枚举? public static bool TryParse(this T enum_type, object value, out T result) where T : struct { return enum_type.TryParse(value, true, out result); } public static bool TryParse(this T enum_type, object value, bool ignoreCase, out T result) where T : struct { result = default(T); var is_converted = false; var is_valid_value_for_conversion = new Func[]{ (e, […]

在ASP.NET中使用Windows身份validation

我正在尝试在ASP.NET应用程序中使用Windows身份validation。 每当我尝试查看应用程序时,它都会将我发送到登录页面。 如何在不通过浏览器手动登录的情况下使其工作? web.config中 更新IIS Express后出错 Most likely causes: No authentication protocol (including anonymous) is selected in IIS. Only integrated authentication is enabled, and a client browser was used that does not support integrated authentication. Integrated authentication is enabled and the request was sent through a proxy that changed the authentication headers before they reach […]

如何访问ThisAddIn类之外的VSTO Outlook加载项中的Application属性?

使用新的Outlook VSTO C#项目创建的ThisAddIn类具有一个Application属性,您可以使用该属性来访问Outlook文件夹和项目。 问题是当你在ThisAddIn类中时可以轻松使用它,但是从项目中的其他类中无法轻松访问它。 这是因为它是一个实例属性。 我想找到访问此属性在我的其他类中提供的相同function的最佳方式,因此我提出了两种可能的解决方案,但我不知道哪一种(如果有的话)是好的。 让我们假设我想要获取默认的收件箱文件夹。 在ThisAddIn类里面我会做这样的事情: this.Application.Session.GetDefaultFolder(Outlook.olFolderInbox); 现在如何在这堂课外做同样的事情? 1.静态属性 首先,我可以向ThisAddIn类添加一个静态属性,并将其设置为我想在其他类中公开的值。 public partial class ThisAddIn { public Outlook.Application OutlookApp; void ThisAddIn_Startup(object sender, EventArgs e) { // init static variable value here OutlookApp = this.Application // initialize the rest of addin here } void InternalStartup() { this.Startup += this.ThisAddIn_Startup; } } 这样在我的任何其他类中我都可以这样做: ThisAddIn.OutlookApp.Session.GetDefaultFolder(Outlook.olFolderInbox); 2.创建新的Application对象 我可以做的第二件事是在我使用它之前在我的其他类中初始化Application对象。 […]

SqlCommand对象,CommandTimeout的时长是多少?

在使用SqlCommand对象时,如何确定使用超时的时间长度? 在我正在处理的部分代码上(由其他人编写)我有: cmd.CommandTimeout = 60; 我觉得这很短暂。 但是,我在论坛上看到一些人谈论将它设置为30000,这似乎太长了。 我怎么知道什么是我的应用程序的最佳选择?

ASP.NET MVC3:强制控制器使用日期格式dd / mm / yyyy

基本上,我的datepicker使用英国格式的dd/mm/yyyy 。 但是当我提交表单时,ASP.net显然使用美国格式。 (只接受少于12天,即认为是月份。) public ActionResult TimeTable(DateTime ViewDate) 有没有办法强迫它识别某种方式? 奇怪的是,其他插入方法似乎认识到正确的格式。 “参数字典包含参数ViewDate的null条目,该参数为非可空类型System.DateTime用于ViewDate中方法System.Web.Mvc.ActionResult Index(System.DateTime) 。可选参数必须是引用类型,可以为空的类型,或者声明为可选参数。“

“否则if()”与C#中的多个“if()”相对应

这些实际上有何不同? // Approach one if (x == 1) DoSomething(); else if (x == 2) DoSomethingElse(); // Approach two if (x == 1) DoSomething(); if (x == 2) DoSomethingElse(); 生成的CIL是否相同? ( 使用“if / elseif / else”与“if / else {if / else}”的问题存在,但尚未得到解答。)

在运行时转换为多个(未知类型)

我正在开发一个能够打开我们通过软件生成的所有自定义文档的查看器。 所有的文件都inheritance自IDocument,但我不确定如何进行反序列化(以一种好的方式 – 嵌套的try / catch可能会起作用,但这很可怕)。 所以我的方法现在看起来像这样: public Boolean OpenDocument(String filename, Type docType, out IDocument document) { // exception handling etc. removed for brevity FileStream fs = null; BinaryFormatter bFormatter = new BinaryFormatter(); fs = new FileStream(filename, FileMode.Open); document = (docType)bFormatter.Deserialize(fs); return true; } 显然这不起作用,因为我不能以这种方式使用变量docType,但我认为它说明了我正在尝试做的事情。 什么是正确的方法去做? 编辑> @John好吧,也许我应该追加另一个问题:如果我有一个界面: public interface IDocument { public Int32 MyInt […]

使用FindControl()来查找控件

我有一个Literal控件,我试图找到它,所以我可以插入文本。 我有一个包含多个内容占位符的母版页面。 Project Navigation 我不断得到“对象引用未设置为对象的实例”。 如何找到此对象以便我可以找到并更新它? 我试过了: ((Literal)Page.FindControl(“litNavLinks”)).Text = sb.ToString(); ((Literal)Page.Page.FindControl(“litNavLinks”)).Text = sb.ToString(); ((Literal)Page.FindControl(“Content7”).FindControl(“litNavLinks”)).Text = sb.ToString(); 无济于事。 我如何确定位置?

IsLittleEndian字段报告错误,但它一定是Little-Endian?

我在英特尔计算机(Win7 64位)上运行,根据我读到的英特尔正在使用Little-Endian。 我在C#中尝试使用以下代码: byte[] b2 = new byte[] { 0, 1 }; short b2short = BitConverter.ToInt16(b2, 0); 和Little-Endian预期的b2short == 256。 然后我在.NET中读到,BitConverter.IsLittleEndian应该反映系统正在使用的endian,当我在Visual Studio中检查变量时,它报告为false ,即它不是Little-Endian。 这与64位操作系统有什么关系吗? 有任何想法吗? 编辑:我的同事,坐在我对面,做了相同的测试(Win Vista 32位),得到了相同的结果 编辑2:这真的很奇怪。 每当我运行代码,并在BitConverter完成它之后中断,IsLittleEndian == false。 但是,如果我添加Console.WriteLine(BitConverter.IsLittleEndian)行; 之后它是真的: byte[] b2 = new byte[] { 0, 1 }; short b2short = BitConverter.ToInt16(b2, 0); Console.WriteLine(BitConverter.IsLittleEndian); // Now the IsLittleEndian is true […]