修改 WCF 客户端代理的端点地址

发布于 2024-10-10 19:52:31 字数 483 浏览 6 评论 0原文

当我使用服务引用从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

脸赞 2024-10-17 19:52:31

由于您已经在使用服务引用,因此您可以简单地使用接受 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.

帅气尐潴 2024-10-17 19:52:31

看起来最好的方法是只使用重载的构造函数之一并自己提供 uri

C = new DataService.SilverlightServiceSoapClient(new BasicHttpBinding(), new System.ServiceModel.EndpointAddress("http://blah/blah/blah/SilverlightService.asmx?Foo=Bar"));

It looks like the best way to do this is to just use one of the overloaded constructors and supply the uri yourself

C = new DataService.SilverlightServiceSoapClient(new BasicHttpBinding(), new System.ServiceModel.EndpointAddress("http://blah/blah/blah/SilverlightService.asmx?Foo=Bar"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文