为什么WCF无法在wcftestclient中调用?

Ela*_*ine 3 wcf

我建立了一个WCF服务,它在IE地址中运行良好,但是一旦我将它添加到wcftestclient并调用一个方法,就会出现错误并显示为:

无法调用该服务.可能的原因:服务离线或无法访问; 客户端配置与代理不匹配; 现有代理无效.有关更多详细信息,请参阅堆栈跟踪.您可以尝试通过启动新代理,还原到默认配置或刷新服务来进行恢复.

错误详情:

The Address property on ChannelFactory.Endpoint was null.  The ChannelFactory's Endpoint must have a valid Address specified.
   at System.ServiceModel.ChannelFactory.CreateEndpointAddress(ServiceEndpoint endpoint)
   at System.ServiceModel.ChannelFactory`1.CreateChannel()
   at System.ServiceModel.ClientBase`1.CreateChannel()
   at System.ServiceModel.ClientBase`1.CreateChannelInternal()
   at System.ServiceModel.ClientBase`1.get_Channel()
   at MyDownloadSvcClient.DeleteMyFolder(Int32 UserId, Int32 FolderId)
Run Code Online (Sandbox Code Playgroud)

配置文件是:(在10/9更新)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <services>
            <service name="MyDownloadSvcClient">
                <endpoint binding="basicHttpBinding" />
            </service>
        </services>
        <bindings />
        <client>
            <endpoint address="http://localhost/MyDownloadSvc.svc"
                binding="basicHttpBinding" bindingConfiguration="" contract="IMyDownloadSvc"
                name="Test" />
        </client>
    </system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)

有什么不对的吗?

提前谢谢,伊莱恩

mar*_*c_s 7

是的,肯定有问题.服务端点WCF必须始终提供ABC - 地址,绑定,合同.您只在配置中定义绑定 - 这正是错误消息所说的 - 您的地址为空.

所以你的配置片段应该类似于:

<system.serviceModel>
    <services>
        <service name="MyDownloadSvcClient">
            <endpoint 
                address="http://localhost:8888/YourService"
                binding="basicHttpBinding"
                contract="IYourServiceContract" />
        </service>
    </services>
Run Code Online (Sandbox Code Playgroud)

地址定义了服务端点住在哪里,在什么地址是提供给外界.如果你没有地址,那么服务就无法与外界交谈.它在哪里服务.如果您使用*.svc文件在IIS中托管服务,则可能会将此地址留空,因为服务地址由*.svc文件所在的服务器和虚拟目录确定 - 但您仍需要提供address=""进入您的服务<service>/<endpoint>标签!

绑定定义了服务交互-什么协议,什么安全设置等-这是如何为您服务的.

最后,合同定义(通过服务合同,通常是服务定义中的接口)调用者可以使用哪些服务方法(功能).您必须提供合同,否则调用者无法知道他可以为您的服务调用哪些方法.这是什么服务的.