我正在尝试在万事达卡的沙箱上请求通过 MoneySend api 付款。这是示例代码,也可以在此处找到c#
问题陈述:
当我尝试直接通过 Visual Studio 发出请求时,它工作得很好,但是当我在 IIS 上部署此服务时,这显示错误
无法解析远程名称:“sandbox.api.mastercard.com”
进一步说明:
在 VS 2017 中创建解决方案,在其中创建 2 个项目,一个服务和另一个用于在控制台中测试相同服务。通过在控制台中指向服务的服务引用,它工作正常。当我在 IIS 上部署服务并将服务端点从本地 VS 链接替换为控制台应用程序中部署的 IIS 链接时,出现上述错误。
更新:
我在一家互联网服务有自己的 dns 和代理设置的公司工作。
完全例外:
MasterCard.Core.Exceptions.ApiException:无法解析远程名称:'sandbox.api.mastercard.com' ---> System.Net.WebException:无法解析远程名称:'sandbox.api.mastercard。 com' at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream() at RestSharp.Http.WriteRequestBody(HttpWebRequest webRequest) at RestSharp.Http.PostPutInternal(String method) at RestSharp.RestClient.Execute (IRestRequest request, String httpMethod, Func`3 getResponse) --- 内部异常堆栈跟踪结束 --- 在 MasterCard.Core.ApiController.Execute(OperationConfig config, OperationMetadata metadata, BaseObject requestMap) 在 MasterCard.Core.Model.BaseObject .Execute[T](字符串操作UUID,T inputObject) at MasterCard.Api.Moneysend.Payment.Create(RequestMap map) at MasterCardWebService.MoneySend.testService() 在 C:\Users\name\Documents\My Received Files\MasterCardWebService\MasterCardWebService\MasterCardWebService\MoneySend.svc.cs :第 128 行
public class PaymentTest
{
public static void Main()
{
string consumerKey = "your consumer key"; // You should copy this from "My Keys" on your project page e.g. UTfbhDCSeNYvJpLL5l028sWL9it739PYh6LU5lZja15xcRpY!fd209e6c579dc9d7be52da93d35ae6b6c167c174690b72fa
string keyAlias = "keyalias"; // For production: change this to the key alias you chose when you created your production key
string keyPassword = "keystorepassword"; // For production: change this to the key alias you chose when you created your production key
var path = MasterCard.Core.Util.GetCurrenyAssemblyPath(); // This returns the path to your assembly so it be used to locate your cert
string certPath = "mypath"; // e.g. /Users/yourname/project/sandbox.p12 | C:\Users\yourname\project\sandbox.p12
ApiConfig.SetAuthentication(new OAuthAuthentication(consumerKey, certPath, keyAlias, keyPassword)); // You only need to set this once
ApiConfig.SetDebug(true); // Enable http wire logging
ApiConfig.SetSandbox(true);
try {
RequestMap map = new RequestMap();
map.Set ("PaymentRequestV3.LocalDate", "0817");
map.Set ("PaymentRequestV3.LocalTime", "150149");
map.Set ("PaymentRequestV3.TransactionReference", "1091774875227082093");
map.Set ("PaymentRequestV3.SenderName.First", "Test");
map.Set ("PaymentRequestV3.SenderName.Middle", "T");
map.Set ("PaymentRequestV3.SenderName.Last", "Test");
map.Set ("PaymentRequestV3.SenderPhone", "7031234567");
map.Set ("PaymentRequestV3.SenderDateOfBirth", "08061977");
map.Set ("PaymentRequestV3.SenderAddress.Line1", "123 Main Street");
map.Set ("PaymentRequestV3.SenderAddress.Line2", "5A");
map.Set ("PaymentRequestV3.SenderAddress.City", "Arlington");
map.Set ("PaymentRequestV3.SenderAddress.CountrySubdivision", "VA");
map.Set ("PaymentRequestV3.SenderAddress.PostalCode", "22207");
map.Set ("PaymentRequestV3.SenderAddress.Country", "USA");
map.Set ("PaymentRequestV3.FundingCard.AccountNumber", "5184680470000023");
map.Set ("PaymentRequestV3.FundingSource", "03");
map.Set ("PaymentRequestV3.AdditionalMessage", "Test");
map.Set ("PaymentRequestV3.ParticipationID", "Test");
map.Set ("PaymentRequestV3.LanguageIdentification", "Tes");
map.Set ("PaymentRequestV3.LanguageData", "Test");
map.Set ("PaymentRequestV3.ReceivingCard.AccountNumber", "5184680430000006");
map.Set ("PaymentRequestV3.ReceiverName.Middle", "B");
map.Set ("PaymentRequestV3.ReceiverName.Last", "Lopez");
map.Set ("PaymentRequestV3.ReceiverAddress.Line1", "Pueblo Street");
map.Set ("PaymentRequestV3.ReceiverAddress.Line2", "PO BOX 12");
map.Set ("PaymentRequestV3.ReceiverAddress.City", "El PASO");
map.Set ("PaymentRequestV3.ReceiverAddress.CountrySubdivision", "TX");
map.Set ("PaymentRequestV3.ReceiverAddress.PostalCode", "79906");
map.Set ("PaymentRequestV3.ReceiverAddress.Country", "USA");
map.Set ("PaymentRequestV3.ReceiverPhone", "1800639426");
map.Set ("PaymentRequestV3.ReceiverDateOfBirth", "06211977");
map.Set ("PaymentRequestV3.ReceivingAmount.Value", "842");
map.Set ("PaymentRequestV3.ReceivingAmount.Currency", "840");
map.Set ("PaymentRequestV3.ICA", "009674");
map.Set ("PaymentRequestV3.ProcessorId", "9000000442");
map.Set ("PaymentRequestV3.RoutingAndTransitNumber", "990442082");
map.Set ("PaymentRequestV3.CardAcceptor.Name", "THE BEST BANK");
map.Set ("PaymentRequestV3.CardAcceptor.City", "ANYTOWN");
map.Set ("PaymentRequestV3.CardAcceptor.State", "MO");
map.Set ("PaymentRequestV3.CardAcceptor.PostalCode", "99999-1234");
map.Set ("PaymentRequestV3.CardAcceptor.Country", "USA");
map.Set ("PaymentRequestV3.TransactionDesc", "P2P");
map.Set ("PaymentRequestV3.MerchantId", "123456");
map.Set ("PaymentRequestV3.ReceiverIdentification.Type", "01");
map.Set ("PaymentRequestV3.ReceiverIdentification.Number", "2147483647");
map.Set ("PaymentRequestV3.ReceiverIdentification.CountryCode", "USA");
map.Set ("PaymentRequestV3.ReceiverIdentification.ExpirationDate", "10102017");
map.Set ("PaymentRequestV3.ReceiverNationality", "USA");
map.Set ("PaymentRequestV3.ReceiverCountryOfBirth", "USA");
map.Set ("PaymentRequestV3.SenderIdentification.Type", "01");
map.Set ("PaymentRequestV3.SenderIdentification.Number", "2147483647");
map.Set ("PaymentRequestV3.SenderIdentification.CountryCode", "USA");
map.Set ("PaymentRequestV3.SenderIdentification.ExpirationDate", "10102017");
map.Set ("PaymentRequestV3.SenderNationality", "USA");
map.Set ("PaymentRequestV3.SenderCountryOfBirth", "USA");
map.Set ("PaymentRequestV3.TransactionPurpose", "01");
Payment response = Payment.Create(map);
Console.WriteLine("Transfer.RequestId--> {0}", response["Transfer.RequestId"]); //Transfer.RequestId-->1413236
Console.WriteLine("Transfer.TransactionReference--> {0}", response["Transfer.TransactionReference"]); //Transfer.TransactionReference-->1091774875227082093
Console.WriteLine("Transfer.TransactionHistory.Transaction[0].Type--> {0}", response["Transfer.TransactionHistory.Transaction[0].Type"]); //Transfer.TransactionHistory.Transaction[0].Type-->PAYMENT
Console.WriteLine("Transfer.TransactionHistory.Transaction[0].SystemTraceAuditNumber--> {0}", response["Transfer.TransactionHistory.Transaction[0].SystemTraceAuditNumber"]); //Transfer.TransactionHistory.Transaction[0].SystemTraceAuditNumber-->212849
Console.WriteLine("Transfer.TransactionHistory.Transaction[0].NetworkReferenceNumber--> {0}", response["Transfer.TransactionHistory.Transaction[0].NetworkReferenceNumber"]); //Transfer.TransactionHistory.Transaction[0].NetworkReferenceNumber-->313371112
Console.WriteLine("Transfer.TransactionHistory.Transaction[0].SettlementDate--> {0}", response["Transfer.TransactionHistory.Transaction[0].SettlementDate"]); //Transfer.TransactionHistory.Transaction[0].SettlementDate-->0818
Console.WriteLine("Transfer.TransactionHistory.Transaction[0].Response.Code--> {0}", response["Transfer.TransactionHistory.Transaction[0].Response.Code"]); //Transfer.TransactionHistory.Transaction[0].Response.Code-->00
Console.WriteLine("Transfer.TransactionHistory.Transaction[0].Response.Description--> {0}", response["Transfer.TransactionHistory.Transaction[0].Response.Description"]); //Transfer.TransactionHistory.Transaction[0].Response.Description-->Approved or completed successfully
Console.WriteLine("Transfer.TransactionHistory.Transaction[0].SubmitDateTime--> {0}", response["Transfer.TransactionHistory.Transaction[0].SubmitDateTime"]); //Transfer.TransactionHistory.Transaction[0].SubmitDateTime-->2016-08-17T09:31:54Z
} catch (ApiException e) {
Console.Error.WriteLine("HttpStatus: {0}", e.HttpStatus);
Console.Error.WriteLine("Message: {0}", e.Message);
Console.Error.WriteLine("ReasonCode: {0}", e.ReasonCode);
Console.Error.WriteLine("Source: {0}", e.Source);
}
}
}