如何从浏览器调用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 = "/getdata", ResponseFormat = WebMessageFormat.Json)] string getdata(); }}
而我的service.svc.cs
:
public bool getdata() { return somenamespace.getfetcheddll(); }
和serviceDll.cs
:
namespace somenamespace{ internal static class UnsafeNativeMethods { _dllLocation = "some.dll"; [DllImport(_dllLocation, CallingConvention = CallingConvention.Cdecl)] public static extern bool OnDecryption(); } public static string getfetcheddll() { return UnsafeNativeMethods.OnDecryption(); }}
我应该如何从浏览器调用getdata()
方法?
我把some.dll
放在同一个项目文件夹中。 我应该在哪里做?
编辑:
我忘了粘贴我的web.config
:
要做到这一点,我按照这个博客: 创建的演练
默认情况下 – HTTP
被转换为wsHttpBinding
,这是一个SOAP服务,所以你不能只是从浏览器调用它。 帮助页面上的?wsdl
后缀似乎也指向了这个方向。
要测试SOAP服务,您需要一个支持SOAP的工具,如Microsoft WCF测试客户端或SoapUI 。
尝试使用WCF测试客户端 – 您是否可以使用该工具通过帮助页面上显示的URL连接到您的服务? 你看到你的服务了吗?