我正在尝试使用我拥有的一个非常简单(基本上是空/无功能)的服务,并使用 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 错误,并且客户端代理未成功生成。任何人都可以看到我目前拥有的任何问题吗?谢谢!