我最近创建了一个WCF服务,并希望使用Silverlight应用程序来使用它。为此,我使用SlSvcUtil(Silverlight 4)来创建必要的客户端类。 但对于每个方法,此工具都会生成一个Request-Object,它具有Method通常需要的所有参数的属性
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服务方法的plain参数,而不使用Request-Object。如何在没有这些请求对象的情况下生成服务方法?
答案 0 :(得分:0)
好的,我终于设法解决了这个难题:
Wether 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));