2009-11-19 144 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。