I have numerous Web Services in my project that share types.
我的项目中有许多共享类型的Web服务。
For simplicity I will demonstrate with two Web Services.
为简单起见,我将使用两个Web服务进行演示。
WebService1 at http://MyServer/WebService.asmx webService2 at http://MyServer/WebService.asmx
WebService1位于http://MyServer/WebService.asmx webService2位于http://MyServer/WebService.asmx
When I generate the proxy for these two services I use:
当我为这两个服务生成代理时,我使用:
wsdl /sharetypes http://MyServer/WebService1.asmx http://MyServer/WebService2.asmx /appsettingurlkey:WebServiceUrl /namespace:MyNamespace /out:MyProxy.cs
WSDL / sharetypes HTTP://MyServer/WebService1.asmx HTTP://MyServer/WebService2.asmx / appsettingurlkey:WebServiceUrl /命名空间:myNameSpace对象/out:MyProxy.cs
The problem is that the appsettingurlkey is the same for each Web Service in the proxy file. I want to be able to specify multiple appsettingurlkey parameters. How is this accomplished? I figure since the /sharetypes parameter became available, there should be a solution for specifying the appsettingurlkey specifically for each Web Service identified.
问题是appsettingurlkey对于代理文件中的每个Web Service都是相同的。我希望能够指定多个appsettingurlkey参数。这是如何完成的?我想,因为/ sharetypes参数可用,所以应该有一个解决方案,专门为每个标识的Web服务指定appsettingurlkey。
If this is not possible with the wsdl.exe, what would you propose I do? I would rather not update the generated code that wsdl.exe outputs and I don't want to go through my whole application passing in the Url to each instance of the Web Services.
如果使用wsdl.exe无法做到这一点,我建议你做什么?我宁愿不更新wsdl.exe输出的生成代码,我也不想通过我的整个应用程序将Url传递给Web Services的每个实例。
3 个解决方案
#1
4
The proxy classes generated are partial classes, so my solution would be to add your own constructor in a different (non-generated) code file, which explicitly reads a different setting for each proxy.
生成的代理类是部分类,因此我的解决方案是在不同的(非生成的)代码文件中添加您自己的构造函数,该文件显式地为每个代理读取不同的设置。
#2
1
To suplement Elijah's own answer, here's the email answer I gave him.
为了补充以利亚自己的答案,这是我给他的电子邮件答案。
I had to blog it because the XML didn't paste well into this text box: http://www.rickdoes.net/blog/archive/2008/09/29/wsdl-shared-types-and-configuration.aspx
我不得不写博客,因为XML没有很好地粘贴到这个文本框中:http://www.rickdoes.net/blog/archive/2008/09/29/wsdl-shared-types-and-configuration.aspx
#3
0
Ahh, instead of creating another partial class with an overloaded constructor passing in the Url, the following additional parameters to the wsdl.exe will solve my problem...
啊,而不是通过传递Url的重载构造函数创建另一个部分类,wsdl.exe的以下附加参数将解决我的问题...
wsdl /sharetypes http://MyServer/WebService1.asmx http://MyServer/WebService2.asmx /appsettingurlkey:WebServiceUrl /namespace:MyNamespace /out:MyProxy.cs /appsettingurlkey:BaseSoapUrl /appsettingbaseurl:http://MyServer/
wsdl / sharetypes http://MyServer/WebService1.asmx http://MyServer/WebService2.asmx / appsettingurlkey:WebServiceUrl / namespace:MyNamespace /out:MyProxy.cs / appsettingurlkey:BaseSoapUrl / appsettingbaseurl:http:// MyServer /
If the web.config has a BaseSoapUrl appSetting, then it will use that to replace the http://MyServer/ sub string from the MyProxy.cs. If the appSetting is not present, then it will just use the path provided in the wsdl.exe (example: {BaseSoapUrl}/WebService1.asmx when using the appSetting or http://MyServer/WebService1.asmx when not using the appSetting).
如果web.config有一个BaseSoapUrl appSetting,那么它将使用它来替换MyProxy.cs中的http:// MyServer / sub字符串。如果appSetting不存在,那么它将只使用wsdl.exe中提供的路径(例如:使用appSetting时的{BaseSoapUrl} /WebService1.asmx或不使用appSetting时的http://MyServer/WebService1.asmx) 。
A thanks goes out to Rick Kierner for pointing me in the right direction.
感谢Rick Kierner指出我正确的方向。
#1
4
The proxy classes generated are partial classes, so my solution would be to add your own constructor in a different (non-generated) code file, which explicitly reads a different setting for each proxy.
生成的代理类是部分类,因此我的解决方案是在不同的(非生成的)代码文件中添加您自己的构造函数,该文件显式地为每个代理读取不同的设置。
#2
1
To suplement Elijah's own answer, here's the email answer I gave him.
为了补充以利亚自己的答案,这是我给他的电子邮件答案。
I had to blog it because the XML didn't paste well into this text box: http://www.rickdoes.net/blog/archive/2008/09/29/wsdl-shared-types-and-configuration.aspx
我不得不写博客,因为XML没有很好地粘贴到这个文本框中:http://www.rickdoes.net/blog/archive/2008/09/29/wsdl-shared-types-and-configuration.aspx
#3
0
Ahh, instead of creating another partial class with an overloaded constructor passing in the Url, the following additional parameters to the wsdl.exe will solve my problem...
啊,而不是通过传递Url的重载构造函数创建另一个部分类,wsdl.exe的以下附加参数将解决我的问题...
wsdl /sharetypes http://MyServer/WebService1.asmx http://MyServer/WebService2.asmx /appsettingurlkey:WebServiceUrl /namespace:MyNamespace /out:MyProxy.cs /appsettingurlkey:BaseSoapUrl /appsettingbaseurl:http://MyServer/
wsdl / sharetypes http://MyServer/WebService1.asmx http://MyServer/WebService2.asmx / appsettingurlkey:WebServiceUrl / namespace:MyNamespace /out:MyProxy.cs / appsettingurlkey:BaseSoapUrl / appsettingbaseurl:http:// MyServer /
If the web.config has a BaseSoapUrl appSetting, then it will use that to replace the http://MyServer/ sub string from the MyProxy.cs. If the appSetting is not present, then it will just use the path provided in the wsdl.exe (example: {BaseSoapUrl}/WebService1.asmx when using the appSetting or http://MyServer/WebService1.asmx when not using the appSetting).
如果web.config有一个BaseSoapUrl appSetting,那么它将使用它来替换MyProxy.cs中的http:// MyServer / sub字符串。如果appSetting不存在,那么它将只使用wsdl.exe中提供的路径(例如:使用appSetting时的{BaseSoapUrl} /WebService1.asmx或不使用appSetting时的http://MyServer/WebService1.asmx) 。
A thanks goes out to Rick Kierner for pointing me in the right direction.
感谢Rick Kierner指出我正确的方向。