使用SOAP访问数据库的最佳方法 [英] best way to access database using SOAP

查看:140
本文介绍了使用SOAP访问数据库的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前的工作,了解用C#SOAP协议,我发现在谷歌的一些例子,了解信封,头部,身体。

I am currently working to understand SOAP protocol with C#, I find some examples in Google and understand the envelope, header, body.

我与web服务进行身份验证,但我想知道我在哪里可以实现一个类或方法所提供的用户名和密码来访问数据库,我的意思是,肥皂头有用户=约翰通=odos223kiwi0X的服务器收到的头,现在访问数据库提供的用户和查询密码。

I authenticate with the webservice but I want to know where can I to implement a class or method to access a database with the user and password provided, I mean, soap header has user="john" pass="odos223kiwi0X" the server received the header, now access to database with the user provided and check the password.

如果一个正确的选择创建的肥皂类的自定义方法做呢?

if a right option create a custom method in the soap Class to do it?

推荐答案

您可以创建一个类,就像下面这样:

you can create a class just as the following :

using System.Diagnostics;
using System.Xml.Serialization;
using System;
using System.Web.Services.Protocols;
using System.Web.Services;
using System.Net;

[System.Web.Services.WebServiceBindingAttribute(
Name = "FunctionName",
Namespace = "nameSpace")]
public class ClassName:
System.Web.Services.Protocols.SoapHttpClientProtocol
{
    public ClassName(string uri) // Constractor
    {
        this.Url = uri; // the full path for your server we  will make later on in the answer
    }

    [System.Web.Services.Protocols.SoapDocumentMethodAttribute(
    "nameSpace/ClassName",
    RequestNamespace = "nameSpace",
    ResponseNamespace = "nameSpace",
    Use = System.Web.Services.Description.SoapBindingUse.Literal,
    ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]

    public object[] FunctionName(string Parameter1)
    {
        object[] results = { };

        try
        {
            results = this.Invoke("FunctionName", new object[] { Parameter1});
            return ((object[])(results[0]));
        }
        catch (Exception error)
        {
            object[] webException = { -1, error.Message };
            return (webException);
        }
    }
}

现在我们创建ASMX服务:

and now we create the asmx service:

创建一个Web服务和命名空间下补充一点:

create a web service and add this under the namespace :

[WebService(Namespace = "NameSpace")] //same namespace you wrote in the class

然后添加功能,并为返回值对象[]。

then add your function and Object[] as returning value.

[WebMethod]
public object[] FunctionName(string Parameter1) // function name and parameters should be the same in your class where you called the web service (case sensitive)
{
   ... // your code
}

**你可以下载 http://www.fiddler2.com/fiddler2/version.asp ,将允许您查看和跟踪走出去请求

** you can download http://www.fiddler2.com/fiddler2/version.asp that will allow you to see and trace the out going requests

请送我回来,如果你需要的任何信息更远

please send me back if you need any farther info.

这篇关于使用SOAP访问数据库的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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