简单的 WCF 服务 - 所有请求都返回空? [英] Simple WCF service - all requests returning empty?

查看:32
本文介绍了简单的 WCF 服务 - 所有请求都返回空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 http://msdn.microsoft.com/en-us/library/bb412178.aspx

Im currently failing at testing a simple WCF service with the WebGet attribute applied, as per the tutorial at http://msdn.microsoft.com/en-us/library/bb412178.aspx

我创建了一个空白的 ASP.NET Web 应用程序项目,然后添加了一个名为test"的 WCF 服务,该服务创建了 test.svcItest.svc.

Ive created a blank ASP.NET web application project, ive then added a WCF service called 'test', which creates test.svc and Itest.svc.

然后我添加了方法hello":

I've then added the method 'hello':

public class test : Itest
{
    public string hello(string s){return "hello " + s;}
}

实现接口:

[ServiceContract]
public interface Itest
{
    [OperationContract]
    [WebGet]
    string hello(string s);
}

但是,对 http://localhost/test.svc/hello?s=hi 的任何请求 (HTTP GET) 都会返回一个空页面.事实上,该 url 下的任何请求都会返回一个空白页面(即 http://localhost/test.svc/abcdefg)

However, any requests (HTTP GETs) to http://localhost/test.svc/hello?s=hi return an empty page. As a matter of fact, any request under that url return a blank page (i.e. http://localhost/test.svc/abcdefg)

我是否遗漏了一些基本的东西?

Am I missing something fundamental?

web.config 完全标准,除了 Visual Studio 生成:

web.config completely standard apart from visual studio generated:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_Itest" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost/test.svc" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_Itest" contract="ServiceReference1.Itest"
        name="BasicHttpBinding_Itest" />
    </client>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

推荐答案

你应该使用 webHttpBinding 代替 basicHttpBinding这是这里的部​​分答案:在浏览器中测试 wcf 服务

You should use webHttpBinding instead to basicHttpBinding Here's part of the answer from here: testing wcf service in browser

这取决于您拥有的 WCF 服务类型:

It depends on what type of WCF service you have:

如果您使用的是 WCF REST 服务 (webHttpBinding),那么您应该能够导航到服务地址,例如http://yourserver/somedir/service.svc

if you're using a WCF REST service (webHttpBinding), then you should be able to just navigate to the service address, e.g. http://yourserver/somedir/service.svc

如果您正在使用其他任何东西,则您有一个 SOAP 服务,并且您无法在 Web 浏览器中测试 SOAP 服务 - 浏览器只是不理解和说 SOAP.但是,您的 C:\ 驱动器中有一个 WCF 测试客户端应用程序,您可以将其用于此目的.

if you're using anything else, you have a SOAP service, and you cannot test a SOAP service in a web browser - the browser just doesn't understand and speak SOAP. There's however a WCF Test Client app in your C:\ drive somewhere which you can use for that purpose.

我可以补充说 WCFTestCLient 在这里:C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\WcfTestClient.exe"

From myself can add that WCFTestCLient is here: "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\WcfTestClient.exe"

这篇关于简单的 WCF 服务 - 所有请求都返回空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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