简体   繁体   English

WP7-将MessageHeader添加到WCF Soap服务调用

[英]WP7 - Adding MessageHeader to WCF Soap Service Calls

I've spent the last two days trying to configure my WP7 app to send message headers to my WCF Soap Service. 最近两天,我一直在尝试配置WP7应用程序以将消息标头发送到WCF Soap Service。 I'm simply trying to send a string of information on every call. 我只是想在每次通话中发送一串信息。

There is an abundance of guides online but I can't seem to piece them together to get what I want done and could really do with some help. 在线上有很多指南,但我似乎无法将它们拼凑起来以完成自己想做的事情,并且确实可以得到一些帮助。

So - could somebody please help me with the SIMPLEST way to add a message inspector to my service and attach headers from within my app? 所以-有人可以通过SIMPLEST方法帮助我向我的服务添加消息检查器并从我的应用程序内附加标头吗?

Thanks! 谢谢!

For WP7 - there's no "simple" way to do that. 对于WP7-没有“简单”的方法可以做到这一点。 Most extensibility points in WCF aren't present in the WP7 platform, so you have a couple of alternatives. WCF中的大多数可扩展点都不存在于WP7平台中,因此您有两种选择。

The easiest way is to use the OperationContext to add outgoing message headers. 最简单的方法是使用OperationContext添加传出消息头。 It's fairly simple (see below), but you need to do that for every operation you call: 这非常简单(请参阅下文),但是您需要为调用的每个操作执行此操作:

var client = new ServiceReference1.MyServiceClient();
client.OperationCompleted += ...;
using (new OperationContextScope(client.InnerChannel))
{
    OperationContext.Current.OutgoingMessageHeaders.Add(
        MessageHeader.CreateHeader(
            "headerName", "http://header.namespace", "the value"));
    client.OperationAsync(param1, param2);
}

If doing that in all operations is too much, an alternative is to create a class which wraps the client, and does that for all the operations. 如果在所有操作中都这样做,那么另一种方法是创建一个包装客户端的类,并对所有操作执行此操作。 Still a lot of code, but at least it will be concentrated in one point, instead of being spread throughout your application. 仍然有很多代码,但是至少它将集中在一个点上,而不是分散在整个应用程序中。

The last alternative (which I can remember now) is to use message inspectors. 最后一种选择(我现在还记得)是使用消息检查器。 They're not part of the platform, but depending on your scenario, I've implemented one support for inspectors / formatters as shown in the blog post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/06/21/wcf-extensibility-extensibility-in-windows-phone-and-silverlight-3.aspx . 它们不是平台的一部分,但是根据您的情况,我已经实现了对检查器/格式化程序的一种支持,如http://blogs.msdn.com/b/carlosfigueira/archive/2011/上的博客文章所示。 06/21 / wcf-extensibility-extensibility-in-windows-phone-and-silverlight-3.aspx For simple scenarios it should work fine. 对于简单的情况,它应该可以正常工作。

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

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