locked
Passing parameter to WCF data service from Windows 8 app? RRS feed

  • Question

  • I want my Windows 8 app to pass a parameter to my wcf data service that sets the connection string. However, all the methods I've found online (such as adding the parameter to the RequestHeader) do not work for Windows 8 app.

    Thanks in advance!

    Thursday, August 30, 2012 6:32 PM

Answers

All replies

  • I'm going to ask one of our guys familiar with WCF to take a look at this post.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, August 31, 2012 2:17 PM
    Moderator
  • Hi Grennerg,

    From what I understand, you want to be able to call a remote WCF Service from a WinRT application and be able to pass a custom HTTP Header (connection string) in the request? If that is the case, you can certainly do that using the following code approach:

    YourWCFClient client = new YourWCFClient(yourBinding, yourEndPointAddress);
    using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
    {
        HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
        httpRequestProperty.Headers["yourCustomHeader"] = "your Connection String";
        OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
        ....
        .... call the client.YourWebMethod here...

    }

    Is this not working for you? Or have I misunderstood your issue? If so, can you clarify further?

    Thanks,

    Prashant.

    • Proposed as answer by Can Bilgin Saturday, September 1, 2012 7:33 AM
    Friday, August 31, 2012 4:45 PM
    Moderator
  • how would I do it if I'm using the entity framework in my wcf service? Like this:

    MyEntities context = new MyEntities(new Uri("http://localohost:12345/MyService.svc));

    And to consume the parameter to set the connection string, I can just override the CreateDataSource() method in my wcf service?

    Sunday, September 2, 2012 10:08 PM
  • You can take a look at the following MSDN forum link that probably goes over the same issue that you are trying to solve: http://social.msdn.microsoft.com/Forums/en/adodotnetdataservices/thread/2eb0e7a8-10c5-4c6c-80b8-23cb39161345

    • Marked as answer by grennerg Thursday, September 6, 2012 4:42 PM
    Tuesday, September 4, 2012 4:29 PM
    Moderator