WCF 不生成属性

发布于 2024-09-04 19:12:23 字数 948 浏览 2 评论 0原文

我有一个 .NET 1.1 ASMX,想在客户端 WinForms 应用程序中使用它。 如果我采用旧方法并将其添加为“WebRefrence”方法,那么我将可以访问它的两个属性,即“url”和“UseDefaultCredentials”,并且它工作正常。 但是,如果我采用新的 WCF 方式并将其添加为 ServiceReference,我仍然可以访问该 ASMX 的方法,但是缺少这两个属性。 原因是什么?

因此,例如,在旧方式(添加 WebReference)中,这些代码是有效的:

    TransferService transferService= new TransferService();
    transferService.Url = "http://something.asmx";
    transferService.Credentials = System.Net.CredentialCache.DefaultCredentials;
    string[] machines = transferService.GetMachines();

但在新方式(添加服务引用)中

    using(TransferServiceSoapClient transferServiceSoapClient = new TransferServiceSoapClient("TransferServiceSoap"))
    {
        transferServiceSoapClient.Url = "someUrl.asmx"; //Cannot resolve URL
        transferServiceSoapClient.GetMachines(new GetMachinesRequest());
        transferServiceSoapClient.Credentials = .... //  //Cannot resolve Credentials
    }

I have a .NET 1.1 ASMX and want to use it in a client WinForms app.
If i go wit the old way and add it as a "WebRefrence" method then I will have access to two of its properties which are "url" and "UseDefaultCredentials" and it works fine.
But if I go with the new WCF way and add it as a ServiceReference I still have access to the methods of that ASMX but those two properties are missing.
what is the reason for that?

so for example in the old way ( adding WebReference) these codes are valid:

    TransferService transferService= new TransferService();
    transferService.Url = "http://something.asmx";
    transferService.Credentials = System.Net.CredentialCache.DefaultCredentials;
    string[] machines = transferService.GetMachines();

But in the new way ( adding Service Reference )

    using(TransferServiceSoapClient transferServiceSoapClient = new TransferServiceSoapClient("TransferServiceSoap"))
    {
        transferServiceSoapClient.Url = "someUrl.asmx"; //Cannot resolve URL
        transferServiceSoapClient.GetMachines(new GetMachinesRequest());
        transferServiceSoapClient.Credentials = .... //  //Cannot resolve Credentials
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短暂陪伴 2024-09-11 19:12:23

因为这些是在 app/web.config 的端点中配置的或以编程方式(如果您愿意)。有关配置 WCF 客户端的详细信息,请参阅此处

Because those are configured in the endpoint in your app/web.config or programatically if you prefer. More on configuring a WCF client here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文