在我的书中,它希望我使用两个绑定公开两个端点:WsHttpBinding 和 NetTCPBinding,并将服务托管在主机应用程序中。
我在 C# 中使用以下代码尝试连接到我的服务:
Uri BaseAddress = new Uri("http://localhost:5640/SService.svc");
Host = new ServiceHost(typeof(SServiceClient), BaseAddress);
ServiceMetadataBehavior Behaviour = new ServiceMetadataBehavior();
Behaviour.HttpGetEnabled = true;
Behaviour.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
Host.Description.Behaviors.Add(Behaviour);
Host.Open();
在服务方面,我有:
[ServiceContract]
public interface IService...
public class SService : IService....
然后在我的配置文件中我有:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="WsHttpBehaviour" name="SService.SService">
<endpoint
address=""
binding="wsHttpBinding"
bindingConfiguration="WsHttpBindingConfig"
contract="SService.IService" />
<endpoint
address=""
binding="netTcpBinding"
bindingConfiguration="NetTCPBindingConfig"
contract="SService.IService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:5640/SService.svc" />
<add baseAddress="net.tcp://localhost:5641/SService.svc" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
但是当我尝试向我的主机应用程序添加服务引用时,它说无法从该地址下载元数据。我不明白出了什么问题,老师从来没有教过这个。我决定继续往下看,提前学习。我使用编辑器创建了上面显示的 WebConfig。
谁能指出我正确的方向?我通过编辑器添加了元数据行为,并将 HttpGetEnabled 设置为 true。