Send information in Soap Header to WCF service in C#

谁说胖子不能爱 提交于 2019-12-25 16:46:30

问题


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.

i read about MessageContract attribute and declared one in the interface file:

[MessageContract]
public class BasicServiceHeader
{
    [MessageHeader]
    public string myString;
}

my WCf interface is:

   [ServiceContract]
public interface IBasicService
{

    [OperationContract]       
    [WebGet(UriTemplate = "GetData?value={value}")]     // Add support for HTTP GET Requests
    string GetData(int value);}

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 ?


回答1:


Client side, you can pass a header prior invoking the operation:

MessageHeader messageHeader = MessageHeader.CreateHeader(_headerName, _headersNameSpace, _headerValue);
OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader);

and extract it using FindHeader service side



来源:https://stackoverflow.com/questions/3734074/send-information-in-soap-header-to-wcf-service-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!