简体   繁体   中英

The remote name could not be resolved: 'sandbox.api.mastercard.com'

I am trying to Make a request on MasterCard's sandbox for payment through MoneySend api. here is the sample code which can also be found here for c#

Problem Statement:

When I am trying to make request through directly visual studio it works perfectly , but when I deployed this service at IIS this show an error

The remote name could not be resolved: 'sandbox.api.mastercard.com'

Further Explanation:

Created Solution in VS 2017, Created 2 projects in it, One of services and other for testing same services in console. By pointing service reference of services in console, it worked fine. When I deployed services on IIS and replaced endpoint of services from local VS link to deployed IIS link in console app, I got above error.

Update:

I am working in a corporation where internet service has its own dns and proxy settings.

Full Exception:

MasterCard.Core.Exceptions.ApiException: The remote name could not be resolved: 'sandbox.api.mastercard.com' ---> System.Net.WebException: The remote name could not be resolved: '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) --- End of inner exception stack trace --- at MasterCard.Core.ApiController.Execute(OperationConfig config, OperationMetadata metadata, BaseObject requestMap) at MasterCard.Core.Model.BaseObject.Execute[T](String operationUUID, T inputObject) at MasterCard.Api.Moneysend.Payment.Create(RequestMap map) at MasterCardWebService.MoneySend.testService() in 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);
            }

        }
    }

Solved by adding proxy to web.config of service project

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

Seems like your DNS is not resolving. You can force it like this:

Open Notepad as Administrator on your server. Browse and open C:\\Windows\\System32\\drivers\\etc\\hosts

At the bottom add: 88.221.244.150 sandbox.api.mastercard.com

Save the file.

The application should now find sandbox.api.mastercard.com .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM