首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SLSvcUtil生成RequestObject

SLSvcUtil生成RequestObject
EN

Stack Overflow用户
提问于 2011-04-05 21:14:21
回答 1查看 275关注 0票数 0

我最近创建了一个WCF服务,并希望使用它与Silverlight应用程序。为此,我使用SlSvcUtil (Silverlight4)创建了必要的客户端类。但对于每个方法,此工具都会生成一个Request-Object,该对象具有该方法通常采用的所有参数的属性

代码语言:javascript
复制
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;
    }

对应的请求类如下所示:

代码语言:javascript
复制
[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

{

代码语言:javascript
复制
[System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://example.com/Namespace", Order = 0)]
public string s;

public DummyRequest()
{
}

public DummyRequest(string s)
{
    this.s = s;
}

}

代码语言:javascript
复制
[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方法的普通参数,而不使用请求对象。如何在没有这些请求对象的情况下生成服务方法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-26 20:30:49

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

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

如果设置:

代码语言:javascript
复制
[ServiceContract]
public interface MyService {
    [OperationContract]
    void MyMethod(Guid id);
}

相应的客户端方法如下所示:

代码语言:javascript
复制
service.BeginMyMethod(id);

但如果您设置:

代码语言:javascript
复制
[ServiceContract(Namespace = "http://example.com/MyService")]
public interface MyService {
    [OperationContract]
    void MyMethod(Guid id);
}

它看起来是这样的:

代码语言:javascript
复制
service.BeginMyMethod(new MyMethodRequest(id));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5552418

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档