【问题标题】:C# - How to add a SOAP web service reference to my project?C# - 如何向我的项目添加 SOAP Web 服务引用?
【发布时间】:2016-05-19 18:39:04
【问题描述】:

我正在尝试将示例项目中的 Web 服务引用添加到我当前的 VS 2015 C# 项目中。这就是我在示例项目中的内容:

要将其移至我的新项目,我尝试通过右键单击我的项目并选择“添加服务参考”来将“地址”字段复制并粘贴到我的项目中。当我这样做时,我收到以下错误:

There was an error downloading 'http://myserver.com/MyServiceExample.svc?wsdl/$metadata'.

The remote name could not be resolved: 'myserver.com'
Metadata contains a reference that cannot be resolved: 'http://myserver.com/MyServiceExample.svc?wsdl/$metadata'.
There was no endpoint listening at 'http://myserver.com/MyServiceExample.svc?wsdl/$metadata that could accept the message. 

This is often caused by an incorrect address or SOAP action.     
See InnerException, if present, for more details.

The remote name could not be resolved: 'myserver.com'
If the service is defined in the current solution, try building the solution    and adding the service reference again.

如何才能将此服务引用添加到我的项目中?我已经尝试使用带有WSDL /verbose 命令的VS 2015 CMD Prompt 添加它,但这似乎不起作用。我有示例的项目文件和 wsdl 文件,但我无法让它们在我的解决方案中工作。

【问题讨论】:

    标签: c# web-services soap service


    【解决方案1】:

    通过启动调试会话在iis express 中启动您的web-service 项目,然后当您获得服务的临时网址(如http://localhost:8000/MyServiceExample.svc)时,您可以从中检索wsdl

    添加服务引用时,只需将myserver.com 部分网址替换为新网址即可。

    Here 您可以阅读添加 service refence 的工作原理,但通常您需要从已部署的 web service (wsdl) 中检索合同,vs 从中生成新类。

    稍后您应该在已部署的服务器上更改 web.config 中的服务 url。

    【讨论】:

    • 您的回答让我走上了正轨。我只是使用了错误的网址。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-12
    • 2011-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    相关资源
    最近更新 更多