1

我正在使用 eBay API 调用GetSessionId方法,但该方法SessionID在我的 ASP.NET MVC4 应用程序中返回空。

谁能帮我解决什么问题?

我正在使用以下代码片段。

 string signinURL = "https://api.sandbox.ebay.com/wsapi";
string callname = "GetSessionID";
string appID = ConfigurationManager.AppSettings["ebay_AppId"];
string version = "768";
string eBayToken = ConfigurationManager.AppSettings["testToken"];
string endpoint = signinURL + "?callname=" + callname +
                    "&appid=" + appID +
                    "&version=" + version +
                    "&routing=default";



eBayAPIInterfaceClient service = new eBayAPIInterfaceClient("eBayAPI", endpoint);
GetSessionIDRequest req = new GetSessionIDRequest();
req.RequesterCredentials = new CustomSecurityHeaderType();

req.RequesterCredentials.Credentials = new UserIdPasswordType();
req.RequesterCredentials.Credentials.AppId = AppConstants.AppId;
req.RequesterCredentials.Credentials.DevId = AppConstants.DevId;
req.RequesterCredentials.Credentials.AuthCert = AppConstants.CertId;
req.RequesterCredentials.eBayAuthToken = AppConstants.ebayToken;
GetSessionIDRequestType reqType = new GetSessionIDRequestType();
reqType.RuName = AppConstants.RuName;
reqType.Version = version;
GetSessionIDResponseType res = service.GetSessionID(ref req.RequesterCredentials, reqType);
if (res.Ack == AckCodeType.Success)
{
    string ebaySignInUrl = "https://signin.ebay.com/ws/eBayISAPI.dll?SignIn&RuName=" + 
                           AppConstants.RuName + "&SessionID=" + res.SessionID;
    Response.Redirect(ebaySignInUrl);
}
4

1 回答 1

0

最后我找出问题所在,问题出在 eBay API 上。它不填充 SessionID 字段。可能是API中的错误。返回值可以在响应对象的 XmlElement Array 字段中找到。所以我在这里得到了 SessionID。

if (response.Any.Length >= 1)
      {
        var SessionId=response.Any.First().InnerText;
      }
于 2014-01-07T11:38:01.907 回答