问题描述
我希望Web应用程序创建对我的WCF服务的服务引用,将信息插入到soap调用的标头中,然后调用我的WCF方法.
i want a web application to create a service reference to my WCF service, insert information to the header of the soap call and call my WCF method.
我了解了MessageContract属性,并在接口文件中声明了一个:
i read about MessageContract attribute and declared one in the interface file:
[MessageContract]
public class BasicServiceHeader
{
[MessageHeader]
public string myString;
}
我的WCf界面是:
[ServiceContract]
public interface IBasicService
{
[OperationContract]
[WebGet(UriTemplate = "GetData?value={value}")] // Add support for HTTP GET Requests
string GetData(int value);}
我不希望将BasicServiceHeader作为GetData函数的参数传递,我想保持该函数不变并在函数内部提取BasicServiceHeader,我可以这样做吗?
i don't want the BasicServiceHeader to be passed as a parameter of GetData function , i want to keep the function as it is and to extract the BasicServiceHeader inside the function, can i do that ?
推荐答案
在客户端,您可以在调用操作之前传递标头:
Client side, you can pass a header prior invoking the operation:
MessageHeader messageHeader = MessageHeader.CreateHeader(_headerName, _headersNameSpace, _headerValue);
OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader);
并使用FindHeader服务端将其提取
and extract it using FindHeader service side
这篇关于将Soap Header中的信息发送到C#中的WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!