简体   繁体   English

部署 C# 项目并在安装时添加 web 服务参考

[英]Deployment of C# project and adding web service reference at the time of installation

I have a requirement in which, application will be referenceing a web service.我有一个要求,应用程序将引用 web 服务。 With each new client installation I need to update the reference manually by opening the project in VSS and re-adding the reference.对于每个新的客户端安装,我需要通过在 VSS 中打开项目并重新添加参考来手动更新参考。

Can I make addition of reference as a part of my installation project or I can add/update the web service reference through code in C#.?我可以添加参考作为我的安装项目的一部分,还是可以通过 C# 中的代码添加/更新 web 服务参考?

I have no experience with creating a setup or msi project.我没有创建设置或 msi 项目的经验。 If someone can also point me to a good tutorial then it will be great..如果有人也可以为我指出一个好的教程,那就太好了..

Just a clarifiction for Service is not changing, Service will be hosted on differnt mahcine,so every time URI is changed.只是澄清一下服务没有改变,服务将托管在不同的机器上,所以每次 URI 都会改变。

Snippet from app config: I need to update the endpoint and servicePrincipalName through code or setup project?来自应用配置的片段:我需要通过代码或设置项目更新端点和 servicePrincipalName?

  <endpoint address="net.tcp://rntn1099:8201/AX/Services/APVendInvoice"
  binding="netTcpBinding" bindingConfiguration="NetTcpBinding_VendVendInvoiceService"
contract="VendInvoiceService.VendVendInvoiceService"     name="NetTcpBinding_VendVendInvoiceService"><identity>  < servicePrincipalName value="host/RNTN1099.corp.xyz.com" />

I have never heard this as an actual requirement.我从来没有听说这是一个实际的要求。 I have heard it from people who don't know that you can choose the URL of the service at runtime.听不懂的人说,运行时可以选择服务的URL。

When you update the service reference, you are actually changing the code of the client.更新服务引用时,实际上是在更改客户端的代码。 This means, at the very least, that all of your tests of the client should take place after the reference update (so that you are testing the code that the client uses).这意味着,至少,您对客户端的所有测试都应该在参考更新之后进行(以便您测试客户端使用的代码)。

When you use "Add Service Reference", at the bottom you enter a Namespace.当您使用“添加服务引用”时,在底部输入一个命名空间。 That will combine with the default namespace for your application to be the namespace in which several classes are created.这将与您的应用程序的默认命名空间相结合,成为创建多个类的命名空间。 For example, if your default namespace is "MyWebApp", and you use "RemoteService" as the namespace in "Add Service Reference", then the namespace will be MyWebApp.RemoteService .例如,如果您的默认命名空间是“MyWebApp”,并且您在“添加服务引用”中使用“RemoteService”作为命名空间,那么命名空间将是MyWebApp.RemoteService You can examine the contents of this namespace by using "View->Object browser" in Visual Studio.您可以使用 Visual Studio 中的“视图->对象浏览器”检查此命名空间的内容。

Now, if the service is named "OrderService", then there will be a class named OrderServiceClient.现在,如果服务名为“OrderService”,那么将有一个名为 OrderServiceClient 的 class。 It has several constructors.它有几个构造函数。 One of those constructors accepts both the configuration name and the URL.其中一个构造函数接受配置名称和 URL。 Another accepts a configuration name and an EndPointAddress .另一个接受配置名称和EndPointAddress You should use one of the two.您应该使用两者之一。

That requirement sounds strange.这个要求听起来很奇怪。 Why do you have to update the reference?为什么必须更新参考? If the service would change it's interface, your client would not work anymore.如果服务会改变它的界面,你的客户端就不能再工作了。 So I assume that your problem is, that you want to access the same service under a differnt url?: If yes.所以我假设你的问题是,你想在不同的 url 下访问相同的服务?:如果是。 You don't have to update the reference.您不必更新参考。 You can configure the service URl without updating the reference.您可以在不更新参考的情况下配置服务 URl。

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

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