如何从浏览器中调用WCF服务OperationContract的? [英] How to call WCF service OperationContract from browser?

查看:2745
本文介绍了如何从浏览器中调用WCF服务OperationContract的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 WCF 4 Web服务和托管在我的 IIS 7 ,我给下面的服务网址:在发布Web节 WCF 项目:

I created a WCF 4 web services and hosted it on my IIS 7, I gave the following Service URL: at publish web section in WCF project:

的http://本地主机:8084 / service1.svc

然后,我结合我发表的网站端口: 4567 和类型: HTTP IIS

Then i bind my published web site on port:4567 and Type: http in IIS.

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

It means that the web service is successfully hosted on IIS. Now i want to call my instances method and return the output at browser. Let me paste you the sample code of Iservice.cs and 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 。 ?我应该在哪里做

I have put the some.dll in the same project folder. Where should i do it?

我已经忘了贴我的 web.config中

<?xml version="1.0"?>
<configuration>
<system.web>
 <compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
  <behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />







要做到这一点,我跟着这个博客:的打造

To do this i followed this blog : walkthrough on creating

推荐答案

在默认情况下 - HTTP 被翻译成的wsHttpBinding 这是一个 SOAP 服务,因此您不能只需调用,从一个浏览器。在?WSDL 后缀的帮助页面上也似乎在那个方向指向。

By default - HTTP is translated into wsHttpBinding which is a SOAP service, so you cannot just call that from a browser. The ?wsdl suffix on the help page also seems to point in that direction.

有关测试的SOAP服务,您需要一个SOAP功能的工具,如微软 WCF测试客户端或<一个HREF =http://www.soapui.org相对=nofollow>了SoapUI

For testing SOAP services, you need a SOAP-capable tool like the Microsoft WCF Test Client or SoapUI.

尝试使用WCF测试客户端 - 可以连接您的网址显示的服务与工具的帮助页面上?你看到你的服务?

Try using the WCF Test Client - can you connect to your service at the URL shown on the help page with that tool? Do you see your service?

这篇关于如何从浏览器中调用WCF服务OperationContract的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆