如何在 C# 中访问复杂类型参数
How to access complex types Argument in C#
我正在尝试使用一项 WCF 服务,因为我们没有 URL 服务,所以我们得到了 XSD 和 WSDL。目前正在为此尝试 POC 的东西。使用 svcutil
工具生成 class 文件。我不太熟悉 WCF 的东西,所以首先尝试在 C# 中使用这些 classes。
下面是我的完整代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace smsclient
{
public interface ISendSms
{
sendMessageResponse1 sendMessage(sendMessageRequest request);
}
public class AccessSMSDetails: ISendSms
{
sendMessageResponse1 ISendSms.sendMessage(sendMessageRequest request)
{
//Here is my implementation code.
sendMessageResponse sresponse = new sendMessageResponse();
sresponse.messageid = 1;
sresponse.recipient = "Chiranjeevi";
sresponse.reference = "reference";
sresponse.status = "sucsesss";
sendMessageResponse1 sresponse1 = new sendMessageResponse1(sresponse);
return sresponse1;
}
}
public class Program
{
static void Main(string[] args)
{
sendMessage sm = new sendMessage();
sm.content = "Content";
sm.destination = "Destination";
sm.reference = "reference";
sendMessageRequest sRequest = new sendMessageRequest(sm);
sendMessageResponse1 sclient = new sendMessageResponse1();
AccessSMSDetails asms = new AccessSMSDetails();
//sclient=
// Here I am not getting the interface Method name to call. Please correct Me if this approach is wrong.
}
}
}
在最后一行我无法调用接口方法。
您正在使用 explicit interface implementation。因此,您需要将 asms
变量转换为相应的接口类型才能工作:
((ISendSms)asms).sendMessage(…);
或者,如果可能的话,使用非显式实现:
public class AccessSMSDetails: ISendSms
{
public sendMessageResponse1 sendMessage(sendMessageRequest request)
{
}
}
然后您可以像往常一样调用该方法:
asms.sendMessage(…);
试试
ISendSms asms = new AccessSMSDetails();
asms.sendMessage(request);
我正在尝试使用一项 WCF 服务,因为我们没有 URL 服务,所以我们得到了 XSD 和 WSDL。目前正在为此尝试 POC 的东西。使用 svcutil
工具生成 class 文件。我不太熟悉 WCF 的东西,所以首先尝试在 C# 中使用这些 classes。
下面是我的完整代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace smsclient
{
public interface ISendSms
{
sendMessageResponse1 sendMessage(sendMessageRequest request);
}
public class AccessSMSDetails: ISendSms
{
sendMessageResponse1 ISendSms.sendMessage(sendMessageRequest request)
{
//Here is my implementation code.
sendMessageResponse sresponse = new sendMessageResponse();
sresponse.messageid = 1;
sresponse.recipient = "Chiranjeevi";
sresponse.reference = "reference";
sresponse.status = "sucsesss";
sendMessageResponse1 sresponse1 = new sendMessageResponse1(sresponse);
return sresponse1;
}
}
public class Program
{
static void Main(string[] args)
{
sendMessage sm = new sendMessage();
sm.content = "Content";
sm.destination = "Destination";
sm.reference = "reference";
sendMessageRequest sRequest = new sendMessageRequest(sm);
sendMessageResponse1 sclient = new sendMessageResponse1();
AccessSMSDetails asms = new AccessSMSDetails();
//sclient=
// Here I am not getting the interface Method name to call. Please correct Me if this approach is wrong.
}
}
}
在最后一行我无法调用接口方法。
您正在使用 explicit interface implementation。因此,您需要将 asms
变量转换为相应的接口类型才能工作:
((ISendSms)asms).sendMessage(…);
或者,如果可能的话,使用非显式实现:
public class AccessSMSDetails: ISendSms
{
public sendMessageResponse1 sendMessage(sendMessageRequest request)
{
}
}
然后您可以像往常一样调用该方法:
asms.sendMessage(…);
试试
ISendSms asms = new AccessSMSDetails();
asms.sendMessage(request);