0

我正在尝试使用我拥有的一个非常简单(基本上是空/无功能)的服务,并使用 svcutil.exe 生成一个代理。这是我的服务器:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.ServiceModel;

class Server2
{
    static void Main(string[] args)
    {
        Console.WriteLine("Server");

        Uri baseAddress = new Uri("http://localhost:1234");
        var host = new ServiceHost(typeof(TheContractService), baseAddress);
        //host.AddServiceEndpoint(typeof(TheContractService), new WSHttpBinding(), "ContractService");
        host.Open();

        Console.ReadLine();
    }
}

[ServiceContract]
class TheContractService
{
    [OperationContract]
    void Expose()
    {
        Console.WriteLine("Exposed");
    }
}

[DataContract]
class TheContract
{
    [DataMember]
    public string PublicProperty { get; set; }
    [DataMember]
    public string PublicField;
    [DataMember]
    private string PrivateProperty { get; set; }
    [DataMember]
    private string PrivateField;
    [DataMember (Name = "BetterName")]
    private string fudshjguhf;
}

现在我只需要设置我的 .config 文件以允许 MEX - 这是我的服务器配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>    
    <services>
      <service name="ContractService"
               behaviorConfiguration="MexServiceBehavior">

        <endpoint address="ContractService"
                  binding="basicHttpBinding"
                  contract="TheContractService"
        />

        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange"
        />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="MexServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>                  
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

我在这里做错了什么?当我尝试运行此命令时: svcutil /t:code http://localhost:1234/mex /out ContractService.cs /config: ContractService.config

我收到 400 或 405 错误,并且客户端代理未成功生成。任何人都可以看到我目前拥有的任何问题吗?谢谢!

4

1 回答 1

0

您的类名是TheContractService,但在您的配置中,元素的name属性是ContractService。确保该属性的值是完全限定的名称(命名空间,如果有的话,加上类名),否则配置将不会被拾取。<service>

于 2012-08-28T22:22:49.903 回答