我有普通的 .NET Web 服务(不是 WCF 服务)。
我已使用服务参考将此服务添加到我的 WP7 项目中,因为我们没有 .通常我们会使用“添加服务引用”选项添加 WCF 服务,但这里我使用“添加服务引用”选项添加普通的 Web 服务。
例如我有这样的服务:
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中调用这样的方法:
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在乐趣2)。当我添加服务引用时,我得到了名称为 Service1SoapClient 的 Service 类(如 TestFun1 函数中的 TestModel 所示),并且我已在 TestFun1() 函数中为该类(在 wp7 中)创建了对象。这个对象(ServiceSoap1Client ) 没有名为的变量msh,但是Service1SoapClient类有函数Fun2Async()和事件Fun2Completed。
我在 Visual Studio 2010 中使用“添加 Web 引用”添加了相同的服务。
在这里,我得到了具有相同名称的服务类,并且我已经为该类创建了对象,在这里我可以获得该变量msh但同样的变量我无法在 WP7 中获得。
Visual Studio 2010 中的 Web 参考代码
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();
}
我的问题是:
1)我使用服务引用添加了普通的Web服务,因为我们没有在适用于Windows Phone的Visual Studio 2010 Express中添加Web引用。这样对吗?
2)我已经使用服务引用添加了正常的Web服务,如果这是正确的方法,我怎样才能获得该变量msh?
3)我已经使用服务引用添加了正常的Web服务,如果这不是正确的方法,我如何在WP7中调用正常的Web服务?
请帮我。
提前致谢。