2009-11-19 58 views
0

我想通過代碼中配置的客戶端連接到WCF服務。主機通過web.config文件進行配置。我得到異常「遠程服務器返回錯誤:(405)方法不允許。」我已經用自託管測試了它,並且它工作正常,但是當它自己運行時,我無法完成它的工作。我試圖讓VS devenv本地託管工作。通過代碼內客戶端連接到WCF的問題

<system.serviceModel> 
    <services> 
     <service name="MyService" behaviorConfiguration="MyServiceBehavior"> 
      <host> 
       <baseAddresses> 
        <add baseAddress="http://localhost:8000/MyService" /> 
       </baseAddresses> 
      </host> 
      <endpoint address="" binding="basicHttpBinding" contract="IMyService" /> 
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name="MyServiceBehavior"> 
       <serviceMetadata httpGetEnabled="True" /> 
      </behavior> 
     </serviceBehaviors> 
     </behaviors> 
</system.serviceModel> 

var uri = new Uri("http://localhost:8000/MyService"); 
var address = new EndpointAddress(uri); 
var factory = new ChannelFactory<IMyService>(new BasicHttpBinding(), address); 
IMyService service = factory.CreateChannel(); 

service.DoSomething(); <-- fails here 

回答

0

想通了。顯然,當使用非自主託管選項時,客戶端端點地址必須在最後包含.svc。