在我的書中,它希望我使用兩個綁定公開兩個終結點: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。
我編輯了你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 – 2013-02-21 18:57:19