简体   繁体   English

向网站添加服务参考

[英]Adding a service reference to a website

I am trying to add a service reference to my website. 我正在尝试向我的网站添加服务参考。 When I add the service reference to a WPF application I get a reference.cs file that I can edit and add attributes to. 当我将服务引用添加到WPF应用程序时,会得到一个reference.cs文件,可以对其进行编辑并向其中添加属性。 When I try to do the same thing in a asp.net website there this file isn't present. 当我尝试在asp.net网站中执行相同的操作时,此文件不存在。 I have also tried looking on the file system and the reference.cs isn't present. 我也尝试在文件系统上查找,但没有reference.cs。 Can anyone provide some guidance? 谁能提供一些指导?

EDIT:: Im using VS2010 and I need to edit the reference.cs to add [Webget] and [WebPost] attributes 编辑::我正在使用VS2010,我需要编辑reference.cs以添加[Webget]和[WebPost]属性

如果要手动编辑服务存根,请考虑使用svcutil.exe

In Visual Studio, right-click on the reference under the "Service Reference" section of the Solution Explorer and click "View in Object Browser". 在Visual Studio中,右键单击解决方案资源管理器的“服务引用”部分下的引用,然后单击“在对象浏览器中查看”。 Then, in the Object Browser, under the namespace for the reference, right-click on any of the properties and select "Go to Definition". 然后,在对象浏览器的引用名称空间下,右键单击任何属性,然后选择“转到定义”。 This will load up "Reference.cs" file. 这将加载“ Reference.cs”文件。

Hope this helps! 希望这可以帮助!

Edit: Also worth noting is that the classes generated for you are partial classes, so it may be beneficial to consider extending them in a separate file so that you can still "Update" the reference and not have the generated code overwrite any changes you make. 编辑:同样值得注意的是,为您生成的类是局部类,因此考虑将它们扩展到单独的文件中可能会有所帮助,这样您仍然可以“更新”引用,而不会让生成的代码覆盖您所做的任何更改。 This would all depend on what you're planing on modifying though. 不过,这全都取决于您打算修改的内容。

Depending on the version of VS it will create a folder under the project root. 根据VS的版本,它将在项目根目录下创建一个文件夹。 In my case under VS2010 I added a ref to http://www.webservicex.net/stockquote.asmx?WSDL , set the namespace to ServiceReference1 and it created a folder in the project root called \\Service References\\ServiceReference1 under which it stored all the ref files including Reference.cs 在VS2010下,我向http://www.webservicex.net/stockquote.asmx?WSDL添加了一个引用,将名称空间设置为ServiceReference1并在项目根目录下创建了一个文件夹\\Service References\\ServiceReference1 ,并将其存储在该文件夹下所有参考文件,包括Reference.cs

If you are not seeing this folder then there may be something wrong at your service that VS is unable to query the WSDL and generate the files. 如果您没有看到此文件夹,则您的服务可能存在问题,VS无法查询WSDL并生成文件。 Try the stock service above to test. 尝试上面的股票服务进行测试。

And editing the generated files is usually a bad idea as they can get regenerated when you refresh the reference. 编辑生成的文件通常是个坏主意,因为刷新参考时可以重新生成它们。 Unless you want to rip the generated code out and never refresh it again. 除非您想撕掉生成的代码,然后再也不刷新它。

UPDATE: 更新:


  • Seems like that webservicex service is slow, try this 好像webservicex服务很慢,请尝试
  • Also, seems like there is a diff between "Web Reference" and "Service Reference". 此外,似乎“ Web参考”和“服务参考”之间存在差异。 See here . 这里 But ultimately it creates a sub folder in your project root called either "Service References" or "Web References" with the sub folder of whatever you named your reference. 但是最终,它会在项目根目录中创建一个名为“服务引用”或“ Web引用”的子文件夹,并使用您命名引用的任何子文件夹。

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

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