我最近创建了一个WCF服务,并希望使用它与Silverlight应用程序。为此,我使用SlSvcUtil (Silverlight4)创建了必要的客户端类。但对于每个方法,此工具都会生成一个Request-Object,该对象具有该方法通常采用的所有参数的属性
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-Project中,这些方法采用Web-Service方法的普通参数,而不使用请求对象。如何在没有这些请求对象的情况下生成服务方法?
发布于 2012-03-26 20:30:49
好了,我终于解开了这个难题:
slsvcutil是否生成这些神秘的请求对象取决于ServiceContractAttribute。
如果设置:
[ServiceContract]
public interface MyService {
[OperationContract]
void MyMethod(Guid id);
}相应的客户端方法如下所示:
service.BeginMyMethod(id);但如果您设置:
[ServiceContract(Namespace = "http://example.com/MyService")]
public interface MyService {
[OperationContract]
void MyMethod(Guid id);
}它看起来是这样的:
service.BeginMyMethod(new MyMethodRequest(id));https://stackoverflow.com/questions/5552418
复制相似问题