使用代码内客户端连接到WCF时出现问题

时间:2009-11-19 22:13:15

标签: .net wcf

我正在尝试使用代码内配置的客户端连接到WCF服务。主机通过web.config文件配置。我得到异常“远程服务器返回错误:(405)方法不允许。”我已经通过自托管对它进行了测试,但它确实有效,但是当它运行在它自己的时候我无法得到它。我试图让它与VS devenv本地主机一起工作。

<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

1 个答案:

答案 0 :(得分:0)

想出来。显然,当使用非自托管选项时,客户端端点地址必须在末尾包含.svc。