无法在 WCF 中创建代理对象
本文关键字:创建 代理 对象 WCF | 更新日期: 2023-09-27 17:56:32
我正在通过以下链接使用 WCF 服务:
http://www.paymentsgateway.com/developerDocumentation/Integration/webservices/merchantservice.aspx#authentication
现在,如果您向下滚动此链接,他们给出了如何创建客户端的示例:
private void CreateClient(int mid)
{
ClientRecord client = new ClientRecord();
client.MerchantID = MerchantID;
client.FirstName = "Bob";
client.LastName = "Smith";
//other code describing client omitted
try
{
using (ClientServiceClient proxy = new ClientServiceClient())
{
int id = proxy.createClient(Authenticate.GetClientAuthTicket(txtID.Text.Trim(), txtKey.Text.Trim()), client);
Response.Write("Created Client ID = " + id.ToString());
}
}
catch (Exception e)
{
Response.Write(e.Message);
}
}
现在我不明白这是什么:ClientServiceClient???我像这样创建了实现:
public static PaymentsGatewayTest.Authentication GetClientAuthTicket (string APILogin, string key)
{
PaymentsGatewayTest.Authentication ticket = new PaymentsGatewayTest.Authentication();
ticket.APILoginID = APILogin;
ticket.UTCTime = DateTime.UtcNow.Ticks.ToString();
ticket.TSHash = GenerateTSHash(ticket.APILoginID + "|" + ticket.UTCTime, key.Trim());
return ticket;
}
private void CreateClient(int mid)
{
ClientRecord client = new ClientRecord();
client.MerchantID = 11245;
client.FirstName = "Bob";
client.LastName = "Smith";
//other code describing client omitted
try
{
using (PaymentsAuthClient proxy = new PaymentsAuthClient())
{
int id = proxy.createClient(Authenticate.GetClientAuthTicket("", "", client));
//Response.Write("Created Client ID = " + id.ToString());
}
}
catch (Exception e)
{
//Response.Write(e.Message);
}
}
我创建了一个名为PaymentsAuthClient的Singleton类,但这似乎不起作用。我在这里做错了什么???
感谢您在ADV:)中的帮助
如果您点击示例源的链接:
http://www.paymentsgateway.com/community/codeSamples/singlepostpage/10-05-05/C_Web_Service_Code_Sample.aspx
您将看到它们具有对客户端 Web 服务的服务引用,并且 ClientServiceClient 由 Visual Studio 从引用自动生成。
他们的例子是服务引用:
https://sandbox.paymentsgateway.net/WS/Client.svc
如果查看 ServiceTestClient'Service References'ClientService
文件夹中的 reference.cs 文件,您将看到客户端被调用:
.....yournamespace.....ClientService.ClientServiceClient
服务名称是命名空间,所以我认为您可能需要:
.....yournamespace.....PaymentsAuthClient.ClientServiceClient