i´ve recently created a WCF-Service and would like to consume it with a Silverlight App. To do so, i used SlSvcUtil (Silverlight 4) to create the necessary client-Side Classes. But for every Method, this tool generates a Request-Object wich has properties for all Parameters the Method usually takes
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;
}
The corresponding Request Classes look like this:
[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)]
pub开发者_如何学Golic partial class DepartmentGetAllRequest
{
public DepartmentGetAllRequest()
{
}
}
In a similar WCF-Project these methods take the plain Parameters of the Web-Service Method, without using a Request-Object. How can I generate the Service-Methods without these Request Objects?
Ok, I finally managed to solve the puzzle:
Wether slsvcutil generates these mysterious request objects or not depends on the ServiceContractAttribute.
If you set:
[ServiceContract]
public interface MyService {
[OperationContract]
void MyMethod(Guid id);
}
the corresponding Client Method looks like this:
service.BeginMyMethod(id);
But if you set:
[ServiceContract(Namespace = "http://example.com/MyService")]
public interface MyService {
[OperationContract]
void MyMethod(Guid id);
}
it looks like this:
service.BeginMyMethod(new MyMethodRequest(id));
精彩评论