简体   繁体   English

如何使用相对路径引用WSDL文件?

[英]How do I reference a WSDL file with a relative path?

I have a WSDL file on disk and loaded as a web reference. 我在磁盘上有一个WSDL文件,并作为Web引用加载。 The problem is that the web reference itself is looking for the WSDL on my machine (using an absolute path), which obviously won't work on teammates' machines. 问题是Web引用本身在我的机器上寻找WSDL(使用绝对路径),这显然不适用于队友的机器。

Is it possible to have the web reference look for the WSDL with a relative path, or from the Resources file? 是否可以让Web引用查找具有相对路径的WSDL,或者从Resources文件中查找? The WSDL is for a third-party service that we've modified to add some extra fields (per their recommendation). WSDL用于我们已修改的第三方服务,以添加一些额外的字段(根据他们的建议)。

When you add a service reference to the WSDL file on your machine, it gets copied into your "Service References" folder in your project. 在计算机上向WSDL文件添加服务引用时,它将被复制到项目的“服务引用”文件夹中。 At that point, the API for your service is determined. 此时,您的服务API已确定。 There is a "Reference.svcmap" (XML) that is created that holds the location of the original location of the WSDL file. 创建了一个“Reference.svcmap”(XML),它保存WSDL文件原始位置的位置。 This is so that you can update the service reference in your project if the API changes. 这样,如果API发生更改,您可以更新项目中的服务引用。 But, even without having that original WSDL file you can check in the code and your team can use it without issue. 但是,即使没有原始的WSDL文件,您也可以检查代码,您的团队可以毫无问题地使用它。 But, if you want them to be able to update the service if the API changes, then you need to actually host that WSDL file in a publicly accessible place. 但是,如果您希望它们能够在API更改时更新服务,那么您需要在公共可访问的位置实际托管该WSDL文件。 Usually, the web service itself provides the WSDL file and you wouldn't have it on your file system. 通常,Web服务本身提供WSDL文件,您不会在文件系统上使用它。 If you plan to update and change the web service, you should connect to the WSDL hosted on a development web server. 如果您计划更新和更改Web服务,则应连接到开发Web服务器上托管的WSDL。 That's really where it belongs, and not a local file. 这就是它所属的地方,而不是本地文件。 But, there's no reason your local file reference wouldn't work just fine until someone tried to update it. 但是,在有人试图更新它之前,没有理由你的本地文件引用不会正常工作。 If your web service never changes, you've got no problem. 如果您的Web服务永远不会改变,那么您就没有问题。 If it could change, then host it somewhere and reference a real URL. 如果它可以改变,那么将它托管在某个地方并引用一个真实的URL。

My initial testing of tweaking the XML in Reference.svcmap file to try for relative path references did not work, but if you decide you really want to get this to work as your question describes, this is the place to make your attempt. 我在Reference.svcmap文件中调整XML以尝试相对路径引用的初步测试不起作用,但是如果您确定要在问题描述的情况下让它工作,那么这就是您尝试的地方。

My suggestion would be to create a programmatic proxy using the cmd line tool wsdl.exe or svcutil.exe to create the .cs or .vb proxy that you could then add to the solution. 我的建议是使用cmd行工具wsdl.exe或svcutil.exe创建一个编程代理,以创建随后可以添加到解决方案中的.cs或.vb代理。

This allows for not needing the wsdl file at all. 这允许根本不需要wsdl文件。 See more information on how here for .NET 2.0 http://msdn.microsoft.com/en-us/library/7h3ystb6(v=vs.80).aspx 有关.NET 2.0的详细信息,请参阅http://msdn.microsoft.com/en-us/library/7h3ystb6(v=vs.80).aspx

for .NET 3.5 or later and svcutil look here: http://msdn.microsoft.com/en-us/library/aa751905.aspx 对于.NET 3.5或更高版本以及svcutil,请访问: http//msdn.microsoft.com/en-us/library/aa751905.aspx

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

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