简体   繁体   English

.NET Web服务-管理Web请求

[英].NET Web Services - managing web requests

I have a .NET WeBService project and a reference to it from another project. 我有一个.NET WeBService项目,另一个项目对此有一个引用。 Visual Studio generates a proxy class (SoapHttpClient) with all methods of my Web Service. Visual Studio使用Web服务的所有方法生成一个代理类(SoapHttpClient)。 The project that I use the WebService from is a .NET CF mobile application. 我使用WebService的项目是.NET CF移动应用程序。 This means that Internet access and WebService is not always available. 这意味着Internet访问和WebService并非始终可用。 What I need to do is to assure that all requests from mobile to the Web Service will finally reach it. 我需要做的是确保从移动设备到Web服务的所有请求最终都能到达它。 I want to do so by queuing all requests to WebService in a worker thread that executes the Web Requests serially until the execution succeedes. 我想通过将对WebService的所有请求排队在一个工作线程中,该线程连续执行Web请求直到执行成功。 The problem is that the generated proxy class has all web methods named. 问题在于生成的代理类具有所有已命名的Web方法。 There is no a mechanism that can "extract" a generic "Web Request object" from the method that I can store for later use. 没有一种机制可以从我可以存储以供以后使用的方法中“提取”通用的“ Web请求对象”。 I have to call the Web Methods explicitly using their names and parameters. 我必须使用其名称和参数显式调用Web方法。 This compilcates my code. 这编译了我的代码。 My question is - Is there a mechanism in .NET WebServices to "extract" a Web Request as an object and us it later? 我的问题是-.NET Web服务中是否有一种机制可以将Web请求“提取”为对象,以后再使用呢?

Regards 问候

Dominik 多米尼克

To my knowledge, .NET generated proxy will not give the web request objects that you want. 据我所知,.NET生成的代理不会提供所需的Web请求对象。 But you can create a simple proxy your self to store the request information and then later use .NET proxy (or SoapHttpClientProtocol class) to make the web request. 但是您可以自己创建一个简单的代理来存储请求信息,然后再使用.NET代理(或SoapHttpClientProtocol类)发出Web请求。 Below is the sample template code: 下面是示例模板代码:

public class MyRequest
{
    public MyRequest(string methodName, params object[] parameters)
    {
        this.MethodName = methodName;
        this.Parameters = parameters;
    }

    public string MethodName { get; set; }
    public object[] Parameters { get; set; }

    public object[] Response {get; set;}
}

public class MyProxy : dotNetGeneratedServiceProxy
{
    List<MyRequest> Requests { get; set; }

    public void QueueMethod1(int param1, string param2)
    {
        Requests.Add(new MyRequest("Method1", param1, param2));
    }

    public void QueueMethod2(string param1)
    {
        Requests.Add(new MyRequest("Method2", param1));
    }

    public void RunAllRequests()
    {
        foreach (var request in Requests)
        {
            var result = this.Invoke(request.MethodName, request.Parameters);
        }
    }
}

Hope this will give you an idea. 希望这会给您一个想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM