无法在WCF中创建代理对象

时间:2011-05-17 02:08:40

标签: c# wcf wcf-client

我正在使用此链接中的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的帮助下:)

1 个答案:

答案 0 :(得分:2)

如果您点击示例来源的链接:

http://www.paymentsgateway.com/community/codeSamples/singlepostpage/10-05-05/C_Web_Service_Code_Sample.aspx

您将看到他们对客户端Web服务有Service Reference,并且Visual Studio会从引用中自动生成ClientServiceClient。

他们的示例是对以下内容的服务引用:

https://sandbox.paymentsgateway.net/WS/Client.svc

如果你查看ServiceTestClient\Service References\ClientService文件夹中的reference.cs文件,你会看到客户端被调用:

.....yournamespace.....ClientService.ClientServiceClient

服务名称是命名空间,所以我认为您可能需要:

 .....yournamespace.....PaymentsAuthClient.ClientServiceClient