简体   繁体   English

从 .NET c# 调用本地 WebService

[英]Call a local WebService from .NET c#

I want consume WebService data from a webforms .NET c# application.我想使用来自 webforms .NET c# 应用程序的 WebService 数据。 The WS is not mine, it have been developed by a third person, who have send me two files: .wsdl and .xsd. WS 不是我的,它是由第三方开发的,他们向我发送了两个文件:.wsdl 和 .xsd。 Then i wanted to try the WS, and used “SOAP UI”.然后我想尝试 WS,并使用“SOAP UI”。 I created a SOAP project loading the .wsdl file and with the .xsd at the same local path.我创建了一个 SOAP 项目,加载 .wsdl 文件和 .xsd 位于同一本地路径。 SOAP UI create fine the XML structure call, and when I put the parameters at the XML call, I receive the response fine too from the WS. SOAP UI 很好地创建了 XML 结构调用,当我将参数放在 XML 调用中时,我也从 WS 收到了很好的响应。

Good, now I need call the WS from my .NET c# application.很好,现在我需要从我的 .NET c# 应用程序调用 WS。 I've using Visual Studio 2010.我使用的是 Visual Studio 2010。

I've been added WS to a Project other times.其他时候我已经将 WS 添加到项目中。 First right click at “References” in the Project structure, click at “Add service reference”, and finally I put the .wsdl local path.首先在Project结构中的“References”上点右键,点“Add service reference”,最后我放的是.wsdl本地路径。 If the .xsd is in the same directory, Visual find the WS with the web methods and I can add the reference correctly.如果 .xsd 在同一目录中,Visual 会使用 Web 方法找到 WS,我可以正确添加引用。 At this point, I have the reference at the “Service references” directory in the project structure, so seems all its OK.此时,我在项目结构中的“服务引用”目录中有引用,所以看起来一切正常。

The problem comes when I try to call the WS methods from any application page, seems as the reference is void, and the namespace associated to the WS not exist.当我尝试从任何应用程序页面调用 WS 方法时,问题就出现了,似乎引用是无效的,并且与 WS 关联的命名空间不存在。

In a aspx.cs file I agree de 'using' with the references added, and when I try to call 'ServiceReference1.”, visual not suggest any, because the namespace is void.在 aspx.cs 文件中,我同意 de 'using' 与添加的引用,当我尝试调用 'ServiceReference1.' 时,visual 不建议任何,因为命名空间是无效的。

Some idea or help please?请提供一些想法或帮助? If is necessary I could show the .wsdl content.如果有必要,我可以显示 .wsdl 内容。

Thanks and regards感谢致敬

I did something similar on a previous project.我在以前的项目中做了类似的事情。 I was calling the WCF service hosted in windows service from a web page.我正在从网页调用 Windows 服务中托管的 WCF 服务。 Only way you can do this is by calling the service on localhost using javascript but there are some tweaks required for enabling cross domain calls and security of your web service.唯一可以做到这一点的方法是使用 javascript 在本地主机上调用服务,但需要进行一些调整才能启用跨域调用和 Web 服务的安全性。 If you want it to work over reference you need to expose your service over a known address and then import it like that into your project.如果您希望它通过引用工作,您需要通过已知地址公开您的服务,然后将其导入到您的项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM