2

我有一个 Web 服务,但需要知道如何在 Windows 应用程序表单中对其进行测试。

这是服务的开始。我会将表单代码放在按钮中,还是将其返回标签?并没有完全理解到 c# 或 .net 我已经成功调用了 Web 服务,只需要返回字符串以确保加密工作正常。

<%@ WebService Language="C#" Class="UserEncryptionLink.EncryptUserLink" %>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Text;
using System.Security.Cryptography;




namespace UserEncryptionLink
{
/// <summary>
   /// This Web Service is to encrypt user details and display them in the URL when  they   click on a link taking them to InfoExchange
/// </summary>
[WebService(Namespace = " Webspace name")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
//To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the    following line. 
[System.Web.Script.Services.ScriptService]







public class EncryptUserLink : System.Web.Services.WebService
{
[WebMethod]
public void TestCypher()
{
    var key = "12345";
    var vector = "12345";
    var username = "YOURDOMAIN\\YOURUSERNAME";
    var url = "sitename.com";
    var it = GetSingleSignOnUrl(url, username, key, vector);
}

还有我的表格

是的,我的表单引用了该服务,它看起来像这样。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FormForEncrypt.nameofURL;
using System.Net;



namespace FormForEncrypt
{


public partial class EncryptForm : Form
{


    public EncryptForm()
    {
        InitializeComponent();


    }

    // creates an instance of the web service as a member of the class, will put it down below, doesn't seem to work though declared in the using statement
    private nameofURL.EncryptUserLink userform = new nameofUrl.EncryptUserLink();



    [System.Web.Services.WebMethod]

    private void testButton_Click_1(object sender, EventArgs e)

    {
        //method to send on button click, then recieve the string to show it works, it should come out as http://CLIENTNAME.info-exchange.com/yyyyMMddHHmmssDomainUsername 

        //create instances of the details


        string[] it;

        //send string

        //recieve string and display, it must display the same as what was sent. 


    }
}

}

4

1 回答 1

0

如果您应该将表单代码放在按钮中或在标签中返回,不确定您的意思是什么?Web 服务没有表单或标签或任何东西的概念。它们只是服务......没有表单,没有控件......只是有点“原始代码”等待通过调用它来提供服务,并且您的托管协议(例如 IIS 或 WAS 或自托管应用程序)负责旋转它并运行服务。

就调用它而言......嗯,这取决于你想从你的应用程序中调用它的位置。可能是单击按钮,可能是计时器,可能是表单加载...取决于您和您的应用程序逻辑。

您当前的 Web 方法 TestChypher 目前不返回任何内容。我猜你需要返回一个布尔值来指示字符串是否匹配?

再次,取决于您和您想要返回的内容。如果您想返回一个字符串,请更改方法签名以返回一个字符串 - 因此将“void”更改为“string”并在该方法中返回您想要返回的字符串。

示例 - 短片:

[WebMethod]
public void SayHello()
{
   return "Hello";
}
于 2013-11-13T11:41:06.030 回答