我需要从DLL中使用WCF服务,因此我没有任何配置文件来从中读取绑定配置。消耗WCF没有app.config
我真的很难得到它的工作。最后,作为一个非常简单的解决办法,我一个引用添加到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();
在本地主机这个简单的工作。当从另一台机器上尝试它,我得到这个错误:
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默认在消息级别保护)。 – 2011-03-04 09:34:10