简体   繁体   English

WCF服务如何获取查询参数?

[英]How can a WCF Service obtain Query Parameters?

I'm working on an Azure service for a Windows Phone app. 我正在为Windows Phone应用程序开发Azure服务。 I need the Azure Service to access the users' OneDrive. 我需要Azure服务来访问用户的OneDrive。 Following this article , my scenario should be: 本文之后 ,我的方案应该是:

After investigating a lot in Service, I still can't find a way to capture the query parameter in my web service. 在调查了很多服务后,我仍然找不到在我的Web服务中捕获查询参数的方法。 As I am new to this area, I don't know where to focus on. 由于我是这个领域的新手,我不知道在哪里关注。 I'll be really appreciated if you can give my an advise or answer my following questions: 如果您能提出建议或回答以下问题,我将非常感激:

  1. Can I access the service just using the url with parameter in a browser? 我可以在浏览器中使用带参数的url来访问服务吗? How can I see if the service is working properly? 如何查看服务是否正常工作?
  2. An article mentioned using WCF [Web Get] attribute to get Query Parameters, but I still don't know how to implement both the IService1.cs and Service1.cs file, could you give me a sample about how to access the value of Query Parameter? 一篇文章提到使用WCF [Web Get]属性获取查询参数,但我仍然不知道如何实现IService1.cs和Service1.cs文件,你能不能给我一个关于如何访问Query值的示例参数?

Thanks! 谢谢!

I'm not sure if i understand your problem properly but if you want your RESTfull WCF service to be the callback receiver for the request code, your Service must be hosted with a WebHttpBinding and a ServiceContract similar to this one. 我不确定我是否正确理解您的问题,但如果您希望RESTfull WCF服务成为请求代码的回调接收器,则您的服务必须使用类似于此的WebHttpBinding和ServiceContract托管。

[ServiceContract]
public interface IService
{
    [WebGet(UriTemplate = "callback?code={requestCode}")]
    void OAuthCallback(string requestCode);
}

So if the base address of your Service is " http://service.mydomain.com/MyService.svc " the OAuthCallback Method will be called when a http GET request to " http://service.mydomain.com/MyService.svc/callback?code=RequestCode " is made. 因此,如果您的服务的基地址是“ http://service.mydomain.com/MyService.svc ”,则当对“ http://service.mydomain.com/MyService.svc ”的http GET请求时,将调用OAuthCallback方法/ callback?code = RequestCode “。

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

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