1

Lets say I have WCF Soap Services and I am using this library for SOAP headers

http://wcfextras.codeplex.com/

For example my interface looks like this

  [SoapHeader("HelperHeader", typeof(HelperHeader), Direction = SoapHeaderDirection.In)]
  [OperationContract]
  string GetData(string id);

    ////////
  public string GetData(string id)
  {
      HelperHeader clientHeader=SoapHeaderHelper<HelperHeader>.GetInputHeader("HelperHeader");
     if (clientHeader != null)
         return id
  }

In Header class i have user name and password for basicHttpbinding. Now i want to use this method "GetData" for REST service . (I also have second webHttbinding) . I want to use this Method "GetData" for REST clients , now i find that i can use attributes WebGet and Webinvoke

  [OperationContract]
  [WebGet(UriTemplate = "testjson/{id}",  ResponseFormat = WebMessageFormat.Json)]
  string GetData(string id);

My quietion is how i can use One Method "GetData" for both REST and SOAP services and with user name and password .?

Beka Tomashvili
  • 2,171
  • 5
  • 21
  • 27
  • possible duplicate of [REST / SOAP endpoints for a WCF service](http://stackoverflow.com/questions/186631/rest-soap-endpoints-for-a-wcf-service) – tom redfern Feb 17 '14 at 14:31
  • But i want how to pass user name and password in REST method .. without passing it in method . – Beka Tomashvili Feb 17 '14 at 15:09
  • You should probably ask a separate question about that. Your question as I read it is *how i can use One Method "GetData" for both REST and SOAP services* which is a duplicate question. The bit about *and with user name and password* is not explained very well and needs further work before you will get good answers. – tom redfern Feb 17 '14 at 15:54

1 Answers1

0

When you create a HttpRequest you can add whatever you want to headers collection:

WebRequest request = WebRequest.Create("<URI>");
request.Headers.Add("username", "<UserName>");
request.Headers.Add("password", "<Pass>");
request.GetResponse();

and in the Service implementation, you can easily access to headers collection by calling this property WebOperationContext.Current.IncomingRequest.Headers

Lukas Kubis
  • 929
  • 5
  • 17