Silverlight SLSvcUtil生成请求对象

Silverlight SLSvcUtil生成请求对象,silverlight,wcf,slsvcutil,Silverlight,Wcf,Slsvcutil,我最近创建了一个WCF服务,并希望通过Silverlight应用程序使用它。为此,我使用SlSvcUtil(Silverlight 4)创建必要的客户端类。 但对于每个方法,该工具都会生成一个请求对象,该对象具有该方法通常采用的所有参数的属性 public System.IAsyncResult BeginDepartmentGetAll(DepartmentGetAllRequest request, System.AsyncCallback callback, object async

我最近创建了一个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
service.BeginMyMethod(id);
service.BeginMyMethod(new MyMethodRequest(id));
{

}


在类似的WCF项目中,这些方法采用Web服务方法的普通参数,而不使用请求对象。没有这些请求对象,我如何生成服务方法?

好的,我终于解决了这个难题:

slsvcutil是否生成这些神秘的请求对象取决于ServiceContractAttribute

如果设置:

[ServiceContract]
public interface MyService {
    [OperationContract]
    void MyMethod(Guid id);
}
[ServiceContract(Namespace = "http://example.com/MyService")]
public interface MyService {
    [OperationContract]
    void MyMethod(Guid id);
}
相应的客户端方法如下所示:

[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
service.BeginMyMethod(id);
service.BeginMyMethod(new MyMethodRequest(id));
但如果您设置:

[ServiceContract]
public interface MyService {
    [OperationContract]
    void MyMethod(Guid id);
}
[ServiceContract(Namespace = "http://example.com/MyService")]
public interface MyService {
    [OperationContract]
    void MyMethod(Guid id);
}
看起来是这样的:

[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
service.BeginMyMethod(id);
service.BeginMyMethod(new MyMethodRequest(id));