本文介绍了如何访问WCF WebServices中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嗨。 我做了一个WCF服务..返回一个XML。 嗯,现在我需要我的WCF服务,返回纯JSON响应我意思是:没有XML标题或标签 这是我在service.vb中的代码: ' 注意:您可以使用上下文菜单中的重命名命令来更改类名代码,svc和配置文件中的服务。 Imports System.Collections.Generic Imports System.Linq Imports System.Runtime.Serialization Imports System.ServiceModel Imports System.Text Imports System .Data.SqlClient Imports System.Configuration Imports System.W eb.Script.Serialization Imports System.ServiceModel.Activation Imports System。 ServiceModel.Web Imports System.Web.Script.Services < AspNetCompatibilityRequirements(RequirementsMode:= AspNetCompatibilityRequirementsMode。允许)> _ 公开 类服务 实现 IService $ b&b< WebInvoke(方法:= POST,ResponseFormat:= WebMessageFormat.Json)> _ 公共 功能 GetPolicyNuic( ByVal Prefijo 作为 字符串, ByVal Folio 作为 字符串, ByVal numVehiculo 作为 字符串, ByVal TipoPoliza 作为 字符串)作为 字符串 实现 IService.GetPolicyNuic Dim DatosPoliza As SqlDataReader = Nothing Dim oConn As 新 dBTools() Dim oPolizas 作为 Poliza oPolizas = 新 Poliza(Prefijo,Folio,numVehiculo,TipoPoliza) 返回(新 JavaScriptSerializer()。序列化(oPolizas)) 结束 功能 结束 班级 在IService.svc中我有: <的ServiceContract()> _ 公开 接口 IService < OperationContract()> ; _ 功能 GetPolicyNuic( ByVal Prefijo As 字符串, ByVal Folio 作为 字符串, ByVal numVehiculo 作为 字符串, ByVal TipoPoliza 作为 String ) As String ' TODO:在此处添加服务操作 结束 接口 b $ b 有人可以告诉我如何访问我的功能? Http://www.mySite.com/wss/WCFService/service.svc/GetPolicyNuic?Prefijo=PBB&Folio=53355&numVehiculo=1&TipoPoliza = A 这是访问我的函数的正确方法吗? 谢谢你。解决方案 尝试 展开 演练:创建和访问WCF服务 [ ^ ] 如何:使用单向和请求 - 回复合同访问WCF服务 [ ^ ] 创建和消费你的第一个WC F服务 [ ^ ] Hi.I made a WCF Service..that return a XML.Well, Right Now I need that my WCF Service, return a pure JSON Response I mean: without XML headers or Tagsthis is my code in service.vb:' NOTE: You can use the "Rename" command on the context menu to change the class name "Service" in code, svc and config file together.Imports System.Collections.GenericImports System.LinqImports System.Runtime.SerializationImports System.ServiceModelImports System.TextImports System.Data.SqlClientImports System.ConfigurationImports System.Web.Script.SerializationImports System.ServiceModel.ActivationImports System.ServiceModel.WebImports System.Web.Script.Services<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _Public Class Service Implements IService <WebInvoke(Method:="POST", ResponseFormat:=WebMessageFormat.Json)> _ Public Function GetPolicyNuic(ByVal Prefijo As String, ByVal Folio As String, ByVal numVehiculo As String, ByVal TipoPoliza As String) As String Implements IService.GetPolicyNuic Dim DatosPoliza As SqlDataReader = Nothing Dim oConn As New dBTools() Dim oPolizas As Poliza oPolizas = New Poliza(Prefijo, Folio, numVehiculo, TipoPoliza) Return (New JavaScriptSerializer().Serialize(oPolizas)) End FunctionEnd Class In the IService.svc I have:<ServiceContract()> _Public Interface IService <OperationContract()> _ Function GetPolicyNuic(ByVal Prefijo As String, ByVal Folio As String, ByVal numVehiculo As String, ByVal TipoPoliza As String) As String ' TODO: Add your service operations hereEnd InterfaceCan someone tell me how I can access to my Functions?Http://www.mySite.com/wss/WCFService/service.svc/GetPolicyNuic?Prefijo=PBB&Folio=53355&numVehiculo=1&TipoPoliza=AThis is the correct way to access to my Functions??Thanks Regards. 解决方案 Try ExpandWalkthrough: Creating and Accessing WCF Services[^]How to: Access WCF Services with One-Way and Request-Reply Contracts[^]Creating and Consuming Your First WCF Service[^] 这篇关于如何访问WCF WebServices中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-29 12:13