使用ADO.Net连接到SQL Server的VB.NET中的WCF服务问题 [英] Problem with WCF Service in VB.NET using ADO.Net in connection to SQL Server

查看:85
本文介绍了使用ADO.Net连接到SQL Server的VB.NET中的WCF服务问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 我有WCF服务"WcfService"除了我的一个负责从sql server获取数据的函数之外,它们的功能很少。我不熟悉vb.net,我的经验来自vba。我在互联网上发现了一些关于
的代码并做了一些小改动,但功能不起作用。我认为问题是ServiceContract()和DataContract()中的错误定义。 Visual Studio Express for Web 2015中的WCF测试客户端向我显示此错误描述"WCF测试客户端不支持此操作
,因为它使用类型WcfService Cookies数据"

 I have WCF service "WcfService" with few functions, they are working good, except my one function which is responsible for getting data from sql server. I'm not good familiar with vb.net, my experience comes from vba. I found some code on the Internet and did some small changes, but function doesn't work. I think the problem is wrong definition in ServiceContract() and DataContract(). WCF Test Client in Visual Studio Express for Web 2015 shows me this error description "This operation is no supported in the WCF Test Client because it uses type WcfService Cookies Data"

IService1.vb。

IService1.vb.

<ServiceContract()>
        Public Interface IService1
          <OperationContract()>
          Function GetCookiesPriceDS(ByVal nameOfCookie As String) As CookiesData
        End Interface
    
    <DataContract()>
    Public Class CookiesData
        Public Sub New()
            CustomersTable = New DataTable("TblCookies")
        End Sub
    
        <DataMember()>
         Public Property CustomersTable() As DataTable
    End Class




Service1.scv


Service1.scv

Imports System.Data.SqlClient
    Imports System.Data
    Imports System.Configuration
    Imports System.ServiceModel
    Imports System.Runtime.Serialization
    Public Class Service1
        Implements IService1
    Public Function GetCookiesPriceDS(ByVal nameOfCookie As String) _
            As CookiesData Implements IService1.GetCookiesPriceDS
    
            Using con As New SqlConnection("Server= xyz\SQLEXPRESS; Database = Cookies2;" &
                " Integrated Security = true;")
                Using cmd As New SqlCommand("select CookiesPrice from tblCookies where " &
                                            "CookiesName='" & nameOfCookie & "'")
                    Using sda As New SqlDataAdapter()
                        cmd.Connection = con
                        sda.SelectCommand = cmd
                        Using dt As New DataTable()
                            Dim ck As New CookiesData()
                            sda.Fill(ck.CustomersTable)
                            Return ck
                        End Using
                    End Using
                End Using
            End Using
        End Function
    End Class

推荐答案

https:// docs。 microsoft.com/en-us/dotnet/framework/wcf/getting-started-tutorial

https://docs.microsoft.com/en-us/dotnet/framework/wcf/getting-started-tutorial

在开始尝试在其中实现SQL查询之前,您可能需要学习WCF的基础知识。

Maybe you need to learn the basics of WCF before jumping off trying to implement a SQL query in it.


这篇关于使用ADO.Net连接到SQL Server的VB.NET中的WCF服务问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆