WCF 不生成属性
我有一个 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为这些是在 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.