修改 WCF 客户端代理的端点地址
当我使用服务引用从 Silverlight 进行 Web 服务调用时,是否有任何方法可以让(生成的)SoapClient 对象修改它们调用服务的地址?
具体来说,我想在服务进行的每个调用上附加一个 QueryString 值。因此,如果我有
DataService.SilverlightServiceSoapClient C = new DataService.SilverlightServiceSoapClient();
是否有任何方法可以执行以下操作:
C.Address += "?Foo=Bar";
这将允许我从我的 WebMethod 中说:
HttpContext.Current .Request.QueryString["foo"];
显然,我可以修改我的 WebMethods 以将此值作为参数,但如果可能的话,我想避免这样做。
When I'm making web service calls from Silverlight using a service reference, is there any way to have the (generated) SoapClient objects modify the address that they call the service on?
Specifically, I'd like to tack on a QueryString value onto each call that the service makes. So if I have
DataService.SilverlightServiceSoapClient C = new DataService.SilverlightServiceSoapClient();
Is there any way to do something like:
C.Address += "?Foo=Bar";
Which would allow me to, from my WebMethod, say:
HttpContext.Current.Request.QueryString["foo"];
Obviously I can modify my WebMethods to take this value in as a parameter, but I'd like to avoid doing that if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您已经在使用服务引用,因此您可以简单地使用接受 EndpointAddress 作为参数的代理类构造函数的重载。或者,您可以创建多个端点配置,并让代码仅使用所选的配置 - 其中可能包括 URL 更改。
请参阅 MSDN 上的了解生成的客户端代码。
Since you are already using service references, you can simply use the overload of the proxy class constructor that accepts an EndpointAddress as a parameter. Alternatively, you can create multiple endpoint configuration and have the code simply use the chosen configuration - which may include URL changes.
See Understanding Generated Client Code on MSDN.
看起来最好的方法是只使用重载的构造函数之一并自己提供 uri
It looks like the best way to do this is to just use one of the overloaded constructors and supply the uri yourself