Callling在WP7正常的网络服务网络服务、正常、Callling

2023-09-03 08:01:04 作者:一骑绝尘灬

我有正常的.NET Web服务(不WCF服务)。

I have normal .NET web service(not a WCF service).

我一直使用服务引用,因为我们没有加入这项服务,我的WP7项目。通常情况下,我们会使用添加服务引用选项添加的WCF服务,但在这里,我补充正常的Web服务使用添加服务引用选项。

I have added this service to my WP7 Project using Service Reference because we don't have . Normally we will add the WCF services using Add Service Reference option but here i added normal Web Service using Add Service Reference option.

例如我有服务是这样的:

For example I have Service like this:

public class Service1
    {
        //local class variable
        public MsgHeader msh;

        //I have two functions like below:
        [WebMethod]
        public int Fun1()
        {
            return 1;
        }
        [WebMethod]
        public int Fun2()
        {
            // Here i am checking msh(MsgHeader) values with the database. 
            //If this information is  not correct i am not proceeding further.
            // some calculations
            return result; //returning some results
        }
    }

我呼吁在WP7这样的方法:

I am calling the methods like this in WP7:

Class TestModel
{
     public void TestFun1()
        {
           RS.Service1SoapClient objRS = new RS.RSService1SoapClient();
            objRS.Fun1Completed += new EventHandler<RS.Fun1CompletedEventArgs>(objRS_Completed);
            objRS.Fun1Async();
        }

    private void objRS_Completed(object sender, EventCompletedEventArgs e)
        {
             string str = e.Result;
             responseEventArgs = new ResponseEventArgs();
                responseEventArgs.response = e.Result;                
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(responseEventHandler, responseEventArgs);
        } 
}

在这里我能够得到的结果成功地为FUN1。但我有一个更多的功能(FUN2)在相同的服务,这是使用服务类变量(如变量 MSH 在FUN2)。当我添加服务引用,我得到我的服务类的名称为Service1SoapClient(如TestFun1功能显示在TestModel),我已经在TestFun1创建该类的对象(WP7)()功能。本对象(ServiceSoap1Client )没有变量名为 MSH ,但Service1SoapClient类具有功能Fun2Async()和事件Fun2Completed。

Here i am able to get the Result Successfully for Fun1. But i have a one more function(Fun2) in same service which is using Service class variables(like variable msh in Fun2). When i add the service reference, i am getting my Service class with the name as Service1SoapClient(as shown in TestModel in TestFun1 function) and i have created the object for that class (in wp7) in TestFun1() function.This object(ServiceSoap1Client) does not have the variable called msh, but Service1SoapClient class has the function Fun2Async() and event Fun2Completed.

我添加使用添加在Visual Studio 2010 Web引用相同的服务。

I have added same service using Add Web Reference in visual studio 2010.

我在这里让我有相同的名称服务类和我创建对象的类,在这里我能够得到这个变量的 MSH 但是我不能够获得在WP7相同的变量。

Here i am getting my Service class with same name and i have created object for that Class, here i am able get that variable msh But same variable i am not able get in WP7.

code。对于在Visual Studio Web引用2010

Private void Test()
{
   SR.Service1 objS=new SR.Service1();
   SR.MsgHeader msh=new SR.MsgHeader();
   msh.Name="test";
   // I have given some more values to msh
   objS.msh=msh;
  int result= objS.Fun2();
}

我的问题是:

My questions are:

1)我一直使用服务引用,因为我们没有在Visual Studio 2010的前preSS添加Web引用为Windows Phone增加正常的网络服务。是不是?

1) I have added normal web service using Service Reference because we don't have add web reference in visual studio 2010 express for windows phone. Is it Right?

2)我已经加入正常的Web服务使用Service参考,如果这是一个正确的方式,我怎么能得到这个变量MSH?

2)I have added normal web service using Service Reference, If it is a right way how can i get that variable msh?

3)我已经添加了正常的Web服务使用Service参考,如果它不是一个正确的方法,我怎么能叫在WP7正常的网络服务?

3)I have added normal web service using Service Reference, If it is not a right way how can i call the normal web service in WP7?

请帮助我。 先谢谢了。

Please help me. Thanks in advance.

推荐答案

我想你混淆的服务器上运行的Web服务类(ES),与由添加服务引用对话框生成的代理类在Visual Studio。

I think you are confusing the web service class(es) that run on the server, with the proxy class that is generated by the 'Add Service Reference' dialog in Visual Studio.

代理类公开,提供了一个方法来调用你的[WebMethod的]在Web服务方法的方法。它不为字段(甚至公共的)这样做。

The proxy class exposes methods that provide a way to call your [WebMethod] methods on the web service. It doesn't do the same for fields (even public ones).

您不会想反正要做到这一点,因为它会造成大比例的问题 - 怎么办?如果两个不同的客户既改变的MSH'的值

You wouldn't want to do this anyway as it would cause big scaling problems - what if two different clients both changed the value of 'msh'?

您会更好过任何状态,你需要为每个服务的方法。

You would be better off passing whatever state you require to each service method.