我最近创建了一个 WCF 服务,并希望通过 Silverlight 应用程序使用它。为此,我使用 SlSvcUtil (Silverlight 4) 创建必要的客户端类。但是对于每个方法,此工具都会生成一个请求对象,该对象具有该方法通常采用的所有参数的属性
public System.IAsyncResult BeginDepartmentGetAll(DepartmentGetAllRequest request, System.AsyncCallback callback, object asyncState)
{
object[] _args = new object[1];
_args[0] = request;
System.IAsyncResult _result = base.BeginInvoke("DepartmentGetAll", _args, callback, asyncState);
return _result;
}
public System.IAsyncResult BeginDummy(DummyRequest request, System.AsyncCallback callback, object asyncState)
{
object[] _args = new object[1];
_args[0] = request;
System.IAsyncResult _result = base.BeginInvoke("Dummy", _args, callback, asyncState);
return _result;
}
相应的请求类如下所示:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName = "Dummy", WrapperNamespace ="http://example.com/Namespace", IsWrapped = true)]
public partial class DummyRequest
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://example.com/Namespace", Order = 0)]
public string s;
public DummyRequest()
{
}
public DummyRequest(string s)
{
this.s = s;
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName = "DepartmentGetAll", WrapperNamespace = "http://example.com/Namespace", IsWrapped = true)]
public partial class DepartmentGetAllRequest
{
public DepartmentGetAllRequest()
{
}
}
在类似的 WCF 项目中,这些方法采用 Web 服务方法的普通参数,而不使用请求对象。如何在没有这些请求对象的情况下生成服务方法?