Selfhosted WCF服务不能通过WCFTestClient测试 [英] Selfhosted WCF service cant be tested via WCFTestClient

查看:152
本文介绍了Selfhosted WCF服务不能通过WCFTestClient测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用WCFTestClient来测试我的自我托管WCF服务。我得到一个错误,像这样:

I am trying to test my self hosted wcf service using WCFTestClient. I get an error like so:

错误:无法从获取元数据的http://本地主机:2303 /为MyService 如果这是Windows(R )通信基础服务,您可以访问,请检查您是否已经启用了元数据发布在指定的地址。为了帮助实现元数据发布,请参阅MSDN文档的的http://去.microsoft.com / fwlink / LINKID = 65455.WS元数据 Exchange错误URI:的http://本地主机: 2303 /为MyService 元数据包含了一个参考,不能解析:HTTP://本地主机:2303 /为MyService。内容类型应用程序/肥皂+ XML; //本地主机:2303 /为MyService 字符集= UTF-8并没有被服务 HTTP支持。客户端和服务绑定可能不匹配。远程服务器返回错误:(415)无法处理邮件,因为内容类型应用程序/肥皂+ XML;字符集= UTF-8是不是预期的类型为text / xml;字符集= UTF-8'.. HTTP GET错误URI:的http://本地主机:2303 /为MyService 有一个错误下载'的http://本地主机:2303 /为MyService。请求失败,HTTP状态400:错误的请求

Error: Cannot obtain Metadata from http://localhost:2303/MyService If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:2303/MyService Metadata contains a reference that cannot be resolved: 'http://localhost:2303/MyService'. Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:2303/MyService. The client and service bindings may be mismatched. The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..HTTP GET Error URI: http://localhost:2303/MyService There was an error downloading 'http://localhost:2303/MyService'. The request failed with HTTP status 400: Bad Request.

我的项目结构如下:

  1. 在控制台应用程序,它作为主机
  2. 服务合同
  3. 服务实施

下面是我的服务实现和合同类,它们是两个独立的项目。

Here are my service implementation and Contract classes, which are in two separate projects.

namespace MyService
{
    public class MyService : IMyService
    {
        public string GetGreeting(string name)
        {
            return "Hello " + name;
        }

        public string GetYelling(string name)
        {
            return "What the hell " + name + "!!";
        }
    }
}

namespace MyService
{
    [ServiceContract]
    public interface IMyService
    {
        [OperationContract]
        string GetGreeting(string name);

        [OperationContract]
        string GetYelling(string name);
    }
}

这是控制台应用程序

namespace MyWCFHost
{
    class Program
    {
        static void Main(string[] args)
        {

            ServiceHost serviceHost = new ServiceHost(typeof(MyService.MyService), new Uri("http://localhost:2303"));
            serviceHost.Open();

            Console.WriteLine("MyService is running...");
            Console.ReadKey();
            serviceHost.Close();
        }
    }
}

这是配置文件

<configuration>

  <system.serviceModel>
    <services>
      <service name ="MyService.MyService" behaviorConfiguration="MyService.MyServiceBehavior">
        <endpoint address="http://localhost:2303/MyService" binding="basicHttpBinding" contract="MyService.IMyService"/>
        <endpoint address="mex" binding="mexHttpBinding" name="mexpoint" contract="IMetadataExchange" />
      </service>

    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="MyService.MyServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>


</configuration>

我是什么做错了吗?

What am I doing wrong?

感谢您的时间...

修改

该服务的工作,当我试图通过一个WinForms客户端上运行,所以我知道该服务工作。问题是我怎么得到它准备好进行测试,以及使用WcfTestClient。

The service works when I try to run it via a winforms client so I know the service is working. Question is how do I get it ready for testing as well, using WcfTestClient.

推荐答案

我怀疑你有一个问题,您的MEX终结。你目前只能指定一个相对地址(MEX) - 但有一个在你的服务定义HTTP无基址......

I suspect you have a problem with your MEX endpoint. You're currently only specifying a relative address ("mex") - but there's no base address for HTTP defined in your service ......

我会建议:

  • 或者定义的基地址,然后上面的只使用相对地址 - 您经常和你的MEX终结

  • 定义您的地址作为全面,完整的地址 - 不只是你的普通终端,但在这种情况下,为MEX端点以及

所以,改变你的配置是这样的:

So change your config to be something like:

<service name ="MyService.MyService" behaviorConfiguration="MyService.MyServiceBehavior">
    <endpoint 
        address="http://localhost:2303/MyService" 
        binding="basicHttpBinding" 
        contract="MyService.IMyService"/>
    <endpoint name="mexpoint" 
        address="http://localhost:2303/MyService/mex" 
        binding="mexHttpBinding" 
        contract="IMetadataExchange" />
  </service>

和那么我希望你应该能够得到你的元数据,从而连接到您服务!

and then I hope you should be able to get at your metadata and thus connect to your service!

这篇关于Selfhosted WCF服务不能通过WCFTestClient测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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