2011-04-05 20 views
0

我最近創建了一個WCF服務並希望將其與Silverlight應用程序一起使用。爲此,我使用了SlSvcUtil(Silverlight 4)來創建必要的客戶端類。 但對於每一個方法,這個工具生成一個請求,對象至極對所有參數的方法通常需要SLSvcUtil生成RequestObject

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服務方法的普通參數,而不使用請求對象。如何在沒有這些請求對象的情況下生成服務方法?

回答

0

好吧,我終於成功地解決了這個難題:

閹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));