远程名称无法解析:'sandbox.api.mastercard.com'

时间:2018-11-08 06:36:30

标签: c# mastercard

我正在尝试通过MoneySend api在万事达卡的沙盒上请求付款。这是示例代码,也可以在{#3}中找到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'          在System.Net.HttpWebRequest.GetRequestStream(TransportContext&context)          在System.Net.HttpWebRequest.GetRequestStream()          在RestSharp.Http.WriteRequestBody(HttpWebRequest webRequest)          在RestSharp.Http.PostPutInternal(String方法)          在RestSharp.RestClient.Execute(IRestRequest请求,字符串httpMethod,Func`3 getResponse)          ---内部异常堆栈跟踪的结尾---          在MasterCard.Core.ApiController.Execute(OperationConfig配置,OperationMetadata元数据,BaseObject requestMap)          在MasterCard.Core.Model.BaseObject.Execute [T](字符串operationUUID,T inputObject)          在MasterCard.Api.Moneysend.Payment.Create(RequestMap地图)上          在MasterCardWebService.MoneySend.testService()中的C:\ Users \ name \ Documents \ My Received中   Files \ MasterCardWebService \ MasterCardWebService \ MasterCardWebService \ MoneySend.svc.cs:line   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);
            }

        }
    }

2 个答案:

答案 0 :(得分:3)

通过在服务项目的web.config中添加代理来解决

<system.net>
    <defaultProxy useDefaultCredentials="false">
      <proxy
        proxyaddress="http://myurladdress:myport"
        bypassonlocal="True"
        usesystemdefault="False"
      />
    </defaultProxy>
</system.net>

答案 1 :(得分:0)

好像您的DNS无法解析。您可以这样强制它:

以管理员身份在服务器上打开记事本。 浏览并打开 C:\ Windows \ System32 \ drivers \ etc \ hosts

在底部添加: 88.221.244.150 sandbox.api.mastercard.com

保存文件。

应用程序现在应该找到 sandbox.api.mastercard.com