为什么在 wcftestclient 中无法调用 WCF? [英] Why WCF cannot be invoked in wcftestclient?

查看:31
本文介绍了为什么在 wcftestclient 中无法调用 WCF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I built up a WCF service, it works good in IE addr, but once i add it to wcftestclient and invoke a method, an error was prompted and shown as :

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

Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.

错误详情:

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)

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

The config file is: (updated at 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>

有什么问题吗?

提前致谢,伊莱恩

推荐答案

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

Yes, there's definitely something wrong. A service endpoint WCF must always supply the ABC - Address, Binding, Contract. You only define the binding in your config - and that's exactly what the error message says - your address is null.

所以你的配置片段应该看起来像:

So your config fragment should look something like:

<system.serviceModel>
    <services>
        <service name="MyDownloadSvcClient">
            <endpoint 
                address="http://localhost:8888/YourService"
                binding="basicHttpBinding"
                contract="IYourServiceContract" />
        </service>
    </services>

地址 定义了服务端点所在的位置,以及可供外界访问的地址.如果你没有地址,那么服务就无法与外界通话.它在WHERE为您提供服务.如果您在 IIS 中使用 *.svc 文件托管您的服务,您可能会将此地址留空,因为服务地址由 *.svc 文件所在的服务器和虚拟目录决定 - 但您仍然需要提供一个address="" 服务入口 / 标签!

The Address defines where the service endpoint lives, at what address it's available to the outside world. If you have no address, then the service cannot talk to the outside where. It's there WHERE of your service. If you host your service in IIS, using a *.svc file, you might be leaving this address empty, since the service address is determined by the server and virtual directory where the *.svc file lives - but you still need to supply an address="" entry to your service <service>/<endpoint> tag!

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

The Binding defines how the service interacts - what protocol, what security settings etc. - it's the HOW of your service.

契约最终定义(通过服务契约,通常是服务定义中的接口)调用者可以使用哪些服务方法(函数).您必须提供合同,否则调用者无法知道他可以在您的服务上调用哪些方法.这是服务的什么.

And the Contract in the end defines (through a service contract, typically an interface in your service definition) what service methods (functions) are available to a caller. You must supply a contract, otherwise the caller has no way of knowing what methods he can call on your service. It's the WHAT of the service.

这篇关于为什么在 wcftestclient 中无法调用 WCF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆