【问题标题】:Connecting to a Gateway Service连接到网关服务
【发布时间】:2012-03-16 18:59:25
【问题描述】:

我正在尝试连接到网关服务:

当我向它说的服务“添加 Web 引用”时,服务会这样说:

HTML 文档不包含 Web 服务发现信息。

网关服务显示如下:

您已经创建了一个服务。

要测试此服务,您需要创建一个客户端并使用它来 致电服务。您可以使用 svcutil.exe 工具从 命令行语法如下:

svcutil.exe http://xxxxxxxxxxxxxxx.com/API/Gateway.svc?wsdl

这将生成一个配置文件和一个代码文件,其中包含 客户端类。将这两个文件添加到您的客户端应用程序并使用 生成的客户端类调用服务。例如:

C#

类测试{ 静态无效主要() { GatewayClient 客户端 = new GatewayClient();

    // Use the 'client' variable to call operations on the service.

    // Always close the client.
    client.Close();
} }

Visual Basic

类测试 共享子主() 昏暗客户端 As GatewayClient = New GatewayClient() ' 使用 'client' 变量调用服务上的操作。

    ' Always close the client.
    client.Close()
End Sub End Class

所以,我尝试连接到这个:

http://xxxxxxxxxxxxxxx.com/API/Gateway.svc?wsdl

这给了我以下列表:

方法 AddABAccount ( ) CloseBatch ( ) CopyVaultAccount ( ) ProcessAccount () ProcessCustomer () ProcessCustomerAndAccount () ProcessTransaction () ProcessVaultTransaction () UpdateABAccount ( )UpdateABSchedule()UpdateTransaction()

所以,我可以添加它...

但是,当我按照他们的建议尝试在代码中连接到它时:

GatewayClient Client = new GatewayClient("wsBinding");
TRANSACTION oT = new TRANSACTION();
GATEWAYRESPONSE oGr = new GATEWAYRESPONSE();
oT.AMOUNT = 1;
oT.TEST = "FALSE"; // When testing, use TRUE
oT.METHOD = "CC"; // We'll use a credit card
oT.ORDERID = GetOrderID(); // Define a unique id for each transaction
oT.CODE = "0000"; // An Auth only transaction
//Process the Transaction
oGr = Client.ProcessTransaction(oT);
//Close the Client
Client.Close();
if (oGr.TRANSACTIONRESPONSE.RESPONSE_CODE == "1")
{
//Handle approved transaction
}
else if (oGr.TRANSACTIONRESPONSE.RESPONSE_CODE == "2")
{
//Handle declined transaction
}
else
{
//Handle transaction error
}

我无法访问 GatewayClient,它说:

无法解析符号“GatewayClient”

在哪里可以找到 GatewayClient!?

【问题讨论】:

  • 您在编译时收到 Cannot resolve symbol 错误,对吗?
  • 在我尝试编译之前,我在 Visual Studio 中得到它。
  • 您在创建服务参考时给它起什么名字?

标签: c# gateway


【解决方案1】:

当添加 Web 引用时,您正在尝试添加对老式 .asmx Web 服务的引用。

您实际尝试引用的服务是 WCF Web 服务 - 从 Visual Studio 2008 开始,添加服务引用时 WCF Web 服务是首选选项(您必须挖掘一些“高级”选项才能添加 . asmx Web 服务)。

要使用为您创建的 Web 服务客户端代理,请确保在您的 using 语句中包含命名空间。

添加Service Reference时设置的默认命名空间是“ServiceReference1”,所以添加

using ServiceReference1;

应该可以解决你的问题。

【讨论】:

  • 啊,这有帮助!我将它添加为 Web 参考而不是服务方法。一旦我这样做了,它就会添加适当的 dll。对 Web 服务的引用存在,但未正确添加。谢谢!
猜你喜欢
  • 1970-01-01
  • 2021-12-15
  • 1970-01-01
  • 2013-06-23
  • 1970-01-01
  • 2014-01-14
  • 1970-01-01
  • 2022-07-28
  • 2014-10-10
相关资源
最近更新 更多