【发布时间】:2011-07-08 16:41:06
【问题描述】:
我需要使用 DLL 中的 WCF 服务,因此我没有任何配置文件可以从中读取绑定配置。
我很难让它发挥作用。最后,作为一个非常简单的解决方案,我添加了对 WCF 的引用并像这样实例化它:
WSHttpBinding binding = new WSHttpBinding();
EndpointAddress address = new EndpointAddress("http://myhost.net/Service.svc");
ServiceReference.ServiceClient client = new ServiceReference.ServiceClient(binding, address);
var result = client.Method1();
在 localhost 中,这很简单。在另一台机器上尝试时,我收到此错误:
The request for security token could not be satisfied because authentication failed.
在主机中,IIS 设置为“匿名”,所以我想它应该可以正常工作。
有什么帮助吗?
编辑:服务配置文件
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<system.serviceModel>
<services>
<service name="Mai.MyPlanner.Service">
<endpoint address="" binding="wsHttpBinding" contract="Mai.MyPlanner.IService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://MY_SERVICE"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<connectionStrings>
<!-- PROD -->
<!-- TEST -->
</connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
【问题讨论】:
-
显示您的服务配置,以便我们查看需要哪些客户端设置。显然,您在服务中使用了一些安全性(默认情况下,WsHttpBinding 在消息级别上是安全的)。
标签: wcf