繁体   English   中英

自主WCF服务无法通过WCFTestClient进行测试

[英]Selfhosted WCF service cant be tested via WCFTestClient

我正在尝试使用WCFTestClient测试我自己托管的wcf服务。 我得到一个错误:

错误:无法从http:// localhost:2303 / MyService获取元数据如果这是您有权访问的Windows(R)Communication Foundation服务,请检查您是否已在指定地址启用元数据发布。 有关启用元数据发布的帮助,请参阅http://go.microsoft.com/fwlink/?LinkId=65455上的MSDN文档.WS- Metadata Exchange错误URI: http:// localhost:2303 / MyService元数据包含引用无法解决:'http:// localhost:2303 / MyService'。 内容类型application / soap + xml; 服务http:// localhost:2303 / MyService不支持charset = utf-8。 客户端和服务绑定可能不匹配。 远程服务器返回错误:(415)无法处理消息,因为内容类型为'application / soap + xml; charset = utf-8'不是预期的类型'text / xml; charset = utf-8'.. HTTP GET错误URI: http:// localhost:2303 / MyService下载'http:// localhost:2303 / MyService'时出错。 请求失败,HTTP状态为400:错误请求。

我的项目结构如下

  1. 作为主机的控制台应用程序
  2. 服务合约
  3. 服务实施

这是我的服务实现和合同类,它们位于两个独立的项目中。

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>

我究竟做错了什么?

谢谢你的时间...

编辑

当我尝试通过winforms客户端运行它时服务工作,所以我知道服务正在运行。 问题是如何使用WcfTestClient为测试做好准备。

我怀疑你的MEX端点有问题。 您目前只指定相对地址(“mex”) - 但是您的服务中没有定义HTTP的基地址......

我建议:

  • 要么定义一个基地址,然后只使用相对地址“on the top” - 对于常规和MEX端点

要么:

  • 将您的地址定义为完整,完整的地址 - 不仅适用于您的常规端点,还适用于MEX端点。

因此,将配置更改为:

<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>

然后我希望你能够获得你的元数据,从而连接到你的服务!

你在运行Windows 7吗?

试试跑步:

netsh http add urlacl url=http://+:2303/MyService user=DOMAIN\user

更多信息和这里

尝试以管理员身份运行Visual Studio。 然后你不需要手动运行像(url = http:// +:2303 / MyService user = PCNAME \\ mylogin)这样的命令

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM