Tag: #wcf

如何从浏览器调用WCF服务OperationContract?

我创建了一个WCF 4 Web服务并将其托管在我的IIS 7 ,我提供了以下Service URL:在WCF项目的发布Web部分: http://localhost:8084/service1.svc 。 然后我将我发布的web site绑定在端口: 4567并在IIS键入: http 。 To checked it i clicked on `web site` at `IIS` and click on the browse. It open a following page at my browser: 这意味着Web服务已成功托管在IIS 。 现在我想调用我的实例方法并在浏览器中返回输出。 让我粘贴Iservice.cs和service.svc.cs的示例代码 #Iservice.cs: namespace some.decryption { [ServiceContract] public interface Iservice { [OperationContract, WebInvoke(Method = “GET”, UriTemplate = […]

未检测到Web服务?

我试图托管这个服务,下面运行正常但是当我在一个不同的Visual Studio运行时打开一个新项目并试图添加一个它找不到任何东西的Web服务? 不是在指定的地址或本地机器上的任何东西? 以下代码似乎只在我在同一个解决方案中运行时才有效? namespace Students { class Program { static void Main(string[] args) { // Create the address for the service Uri address = new Uri(“http://localhost:8001”); // Create the binding for the service WSHttpBinding binding = new WSHttpBinding(); // Create the service object StudentService service = new StudentService(); // Create the host for the […]

WCF Restful服务是否允许同样的方法公开为WebGet和WebInvoke?

WCF Restful服务是否允许同样的方法暴露为WebGet和WebInvoke,如方法重载? 这两种方法都可以从同一个URL访问。 对于Ex。 [ServiceContract] public interface IWeChatBOService { [WebGet(UriTemplate = “WeChatService/{username}”)] [OperationContract] string ProcessRequest(string MsgBody); [WebInvoke(Method = “POST”, UriTemplate = “WeChatService/{username}”)] [OperationContract] string ProcessRequest(string MsgBody); 是否可以使用WCF Restful Service?

服务引用不是创建方法

我正在尝试将SOAP Web服务的服务引用添加到我的ASP.NET MVC应用程序中,因此我可以从此处使用Web服务。 问题是,服务引用没有创建我可以在常规应用程序中使用的任何类或方法,它只定义了两个接口和许多数据类型。 也许我错了,但是正如我理解的那样,服务引用应该创建一个类,我可以使用它来调用服务上的不同方法。 然后我的工作是将我的业务模型数据转换为Web服务的数据类型,以便我可以向方法发送参数并使用它们的响应。 我做错了,应该使用不同的方法来使用外部SOAP Web服务吗?

使用IParameterInspector.BeforeCall(字符串operationName,object 输入)中止调用

我有一个自定义行为,我实现“IParameterInspector”,以便能够使用BeforeCall和AfterCall。 我正在使用这些方法在我的WCF服务上执行调用之前进行一些validation。 这是我的属性: [AttributeUsage(AttributeTargets.Class)] public class SendReceiveBehaviorAttribute : Attribute, IServiceBehavior { public SendReceiveBehaviorAttribute() { } public void ApplyDispatchBehavior(ServiceDescription desc, ServiceHostBase host) { foreach (ChannelDispatcher cDispatcher in host.ChannelDispatchers) { foreach (EndpointDispatcher eDispatcher in cDispatcher.Endpoints) { foreach (DispatchOperation op in eDispatcher.DispatchRuntime.Operations) { op.ParameterInspectors.Add(MyInspector); } } } } public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection endpoints, BindingParameterCollection bindingParameters) […]

WCF。 IList被反序列化为数组。 如何使它成为任何可写列表(ArrayList)?

我有一个客户端 – 服务器应用程序,其中一部分通过WCF(netTcp绑定)相互“交谈”。 我有我的DataContract,它有一个第三方类的字段: [Serializable] public class MyResult{ public ThirdPartyResult Result {get;set;} /* other fields */ } 使用reflection我看到这个: [Serializable] public class ThirdPartyResult { private IList result; public IList Result { get { return result ?? (result = new ArrayList());} } } 从客户端调用服务器时,我将result作为服务器上的ArrayList 。 在客户端之后, result字段变为固定大小的数组。 我没有使用添加服务引用 ,但我使用程序集共享,只是这样做 ChannelFactory.CreateChannel(new NetTcpBinding(“Configuration.Name”), address); 更新:服务合同 [ServiceContract] [ServiceKnownType(typeof(ArrayList))] [ServiceKnownType(typeof(ThirdPartyResult))] public […]

在WCF中添加具有netsh的端口作为没有管理员权限的域管理员

我在WPF应用程序(自托管)中有一个WCF服务,我有一个典型的错误“你的进程没有对这个命名空间的访问权限”。 用户不能拥有管理员权限,因此使用.manifest不是解决方案。 端口是动态的,应用程序每次运行时都会计算一个空闲端口,因此应用程序必须通过netsh多次插入监听端口我使用带有域管理员的ProcessStartInfo,但要启动该过程,用户需要管理员权限。 以管理员身份运行应用程序既不是解决方案,所以我需要普通用户可以运行应用程序,程序通过netsh作为域管理员添加端口。 我的过程是这样的: ProcessStartInfo psi = new ProcessStartInfo(“netsh”, parameter); SecureString ss = new SecureString(); for (int i = 0; i < adminPass.Length; i++) ss.AppendChar(adminPass[i]); psi.Password = ss; psi.UserName = Admin; psi.Domain = Domain; psi.Verb = "runas"; psi.RedirectStandardOutput = false; psi.CreateNoWindow = true; psi.WindowStyle = ProcessWindowStyle.Hidden; psi.UseShellExecute = false; Process.Start(psi); 非常感谢

没有TLS 1.0,WCF .NET 4.0无法运行

在我工作的公司中,我们有一个产品在.NET Framework 4.0中使用SSL使用WCF over net.tcp。 在特定客户端中,出于安全原因,存在禁用SSL 2,SSL 3和TLS 1的要求。问题是没有TLS 1.0,通信不起作用。 有人可以告诉我为什么? 我使用IISCrypto来禁用上述协议。 它在本讨论中附带了示例代码。 重现场景的步骤。 禁用协议,如下图所示 重新启动计算机 构建附加的解决方案 执行Server.exe 执行Client.exe 它将显示以下错误:调用者未通过该服务进行身份validation

如何唯一标识在会话0中运行的Internet Explorer窗口?

我正在创建自动化internet explorer WCF web services 。 有多个Web服务调用需要访问Internet Explorer的同一实例。 但是,由于WCF服务托管在IIS所有对Web服务的调用都在会话0中执行。现在要访问Internet Explorer的同一实例,我使用SHDocVw.InternetExplorer.HWND属性返回Internet Explorer实例的窗口句柄。 在下面的代码中,当作为IIS 7上的WCF服务执行时,由于会话0隔离,窗口句柄始终返回0。 此外,我无法挂钩到相同的IE实例或循环所有打开的IE窗口。 我可以枚举进程列表并查找在会话0中打开的每个IE窗口的进程ID,但不能将System.Diagnostics.Process为SHDocVw.InternetExplorer对象。 以下是我的代码: public int GetWhd() { InternetExplorer ie = new InternetExplorer(); ie.Visible = true; return ie.HWND; } public int SetWhd(string whd) { int wh = Int32.Parse(whd); InternetExplorer ie = null; ShellWindows s = new ShellWindows(); foreach (SHDocVw.InternetExplorer ie1 in s) { […]

jquery ajax’post’来电

我是jQuery和Ajax的新手,我遇到了’post’的问题。 我正在使用jQuery Ajax“post”调用将数据保存到数据库。 当我尝试保存数据时,它将null传递给我的C#方法。 jQuery看起来像这样: function saveInfo(id) { var userID = id; var userEmail = $(‘.userEmail’).val(); var userName = $(‘.userName’).val(); var dataJSON = {“userID”: userID, “userEmail”: userEmail, “userName”: userName}; $.ajax({ type: ‘POST’, url: ‘../../Services/AjaxServices.svc/SaveUser’, data:JSON.stringify(dataJSON), contentType: ‘application/json; charset=utf-8’, dataType: ‘json’ }); return false; }` .userEmail和.userName是对输入字段的类引用。 C#代码如下所示: [ServiceContract(Namespace = “http://testUsePage.com”)] [AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)] public class AjaxServices { [OperationContract] […]