简体   繁体   English

将查询参数传递给WCF服务

[英]Passing in query parameters to a WCF Service

I'm slight confused on how to do this. 我对如何执行此操作感到有些困惑。 I've followed some examples after searching but still cant get this working then again most examples seem to target Json (not sure if that would make a difference). 在搜索之后,我遵循了一些示例,但是仍然无法正常工作,然后大多数示例似乎都针对Json(不确定是否会有所作为)。

Im using basicHttpBinding. 我正在使用basicHttpBinding。

So i have a simple Interface: 所以我有一个简单的界面:

<ServiceContract()>
 Public Interface ICustomersService
<OperationContract()>
<WebGet(UriTemplate:="SaveName/{name}")> 
Sub SaveName(ByVal name as string)

Next i create my hosting application which works and i can reach the WSDL page and can view SaveName. 接下来,我将创建可以运行的托管应用程序,并且可以访问WSDL页面并可以查看SaveName。

The current URL is http://example.com/ 当前网址是http://example.com/

I would like to pass in a name which then saves to the database. 我想输入一个名称,然后将其保存到数据库中。 Im expecting the URL to be along the lines of 我希望该网址与

http://example.com/SaveName?name="Tony"

That doesnt work so i tried a couple of variations using standard query string parameters but non work. 那不起作用,所以我尝试了使用标准查询字符串参数的几种变体,但是不起作用。

Am i doing something wrong or is there a step missing? 我是在做错事还是缺少步骤?

To use the WebGet / WebInvoke attributes, you cannot use a basicHttpBinding (or, you can use it, but those attributes will be ignored). 要使用WebGet / WebInvoke属性,不能使用basicHttpBinding (或者,可以使用它,但是那些属性将被忽略)。 BasicHttpBinding is one of the bindings that use the SOAP protocol, and it has some strong requirements regarding the format of the message (in a nutshell, almost everything goes in the request body, and some addressing parameters may go in HTTP headers). BasicHttpBinding是使用SOAP协议的绑定之一,它对消息的格式有一些严格的要求(简而言之,几乎所有内容都在请求正文中,而某些寻址参数可能在HTTP标头中)。

To be able to define your endpoint operations using the WebGet attribute, your endpoint needs to use the webHttpBinding , and it also needs to have the <webHttp/> behavior applied to it ( WebHttpBehavior , if you're defining your endpoint via code). 为了能够使用WebGet属性定义端点操作,端点需要使用webHttpBinding ,并且还需要对其应用<webHttp/>行为( WebHttpBehavior ,如果要通过代码定义端点)。

One more thing worth pointing out: if you use a "web" endpoint, the WSDL will not have all the information that you need to connect a client to it, so you won't be able to use the "WCF test client" to talk to it. 还有一件值得指出的事情:如果您使用“ Web”端点,则WSDL将不具备将客户端连接到该端点所需的所有信息,因此您将无法使用“ WCF测试客户端”来跟它说话。 More information about it at this blog post . 有关此博客的更多信息。

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

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