我需要從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