我正在构建一个带有url的POST方法的WCF REST服务:
http://localhost:8888/application/list_i/{agent_name}
发布参数:用户名和密码
现在,虽然我能够通过Stream类型获取用户名和密码,但我无法使UriTemplate匹配,因为它认为agent_name也应该是一个post变量,而,它是一个get变量,是请求URL的一部分。
运营合同
Imports System.ServiceModel
Imports System.IO
<ServiceContract()>
Public Interface IMobileAppService
<OperationContract()>
Function IndividualCases(ByVal stream As Stream) As ArrayList
End Interface
服务类
Imports System.ServiceModel
Imports System.ServiceModel.Web
Imports MySql.Data.MySqlClient
Imports System.IO
Imports System.Collections.Specialized
Imports System.Web
' NOTE: You can use the "Rename" command on the context menu to change the class name "MobileAppService" in both code and config file together.
Public Class MobileAppService
Implements IMobileAppService
Dim mysqlconnection As New MySqlConnection("server=localhost; user id=root; password= ; database=dattaibm;")
<WebInvoke(Method:="POST", ResponseFormat:=WebMessageFormat.Json, BodyStyle:=WebMessageBodyStyle.Bare, UriTemplate:="/application/list_i/{agent_name}")>
Public Function IndividualCases(ByVal stream As Stream) As ArrayList Implements IMobileAppService.IndividualCases
Dim request As NameValueCollection = processStream(stream)
Dim response As New ArrayList
response.Add(New IndividualCase With {.activity_id = "00001", .customer_name = request("username")})
response.Add(New IndividualCase With {.activity_id = "00002", .customer_name = request("password")})
response.Add(New IndividualCase With {.activity_id = "00003", .customer_name = "00003"})
Return response
End Function
End Class
最后,UriTemplate与我通过Rest Client ping的任何内容都不匹配。 有人可以帮忙吗?这是我第一次涉足WCF服务。
由于
更新:
我的app.config,如果需要:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="MobileAppService.MobileAppService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8888/" />
</baseAddresses>
</host>
<endpoint address="http://localhost:8888/" binding="webHttpBinding" contract="MobileAppService.IMobileAppService"/>
</service>
</services>
</system.serviceModel>
</configuration>
注意:我在控制台应用中将其作为自托管WCF服务运行。