2015-09-14 27 views
0

Apple在今年8月15日发布了新一代WSDL,最大的变化是每次调用WSDL都必须使用证书进行验证文件。如何将X509Certificate2附加到webservice(Apple GSX/C#specific)

我已经完成了从Apple获取证书的过程,并且我已将我们的服务器IP列入白名单,并且我甚至验证了我可以通过使用简单的接口编码来访问服务端点HttpWebRequest可以轻松地使用webRequest.ClientCertificates.Add()附加证书,所以我知道一切都准备好了。

但是,当我从https://gsxwsut.apple.com/apidocs/prod/html/WSArtifacts.html?user=asp

下载WSDL我的问题出现我导入WSDL到Visual Studio,当我试图让客户端类的一个实例,是唯一一个我觉得是GsxWSEmeaAspPortClient,这似乎因为它具有验证和各种工具的所有功能,但它没有ClientCertificates。它的ClientCredentials有ClientCertificate,但是当我尝试在那里设置证书时,就像它从未设置过一样。

我猜服务代码通过HttpWebRequest或WebRequest传输数据,所以如果我只是可以从类的实例(GsxWSEmeaAspPortClient)得到请求代码,我可以修复它,但我不能似乎到达那里。

我看了这个问题:How can I connect with Apple's GSX NewGeneration webservices with WCF?这表明它确实应该很容易,但我没有GsxWSEmeaAspService,只有我的Visual Studio生成的WSDL中的GsxWSEmeaAspPortClient。

如果任何人有任何想法可以指向我的任何方向朝胜利,我会永远感激。

我使用Visual Studio 2013,解决方案是.Net v4.5.1,如果这有什么区别。

回答

0

我粘贴新的代码在这里:

public void Authenticate() { 
    // Use custom binding with certificate authentication 
    BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); 
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate; 
    // Create service endpoint 
    // Use proper endpoint address - eg. gsxapi.apple.com for production 
    EndpointAddress endpoint = new EndpointAddress("https://gsxapiit.apple.com/gsx-ws/services/emea/asp"); 
    // Create new service 
    Apple.GsxWSEmeaAspPortClient service = new Apple.GsxWSEmeaAspPortClient(binding, endpoint); 
    // Set loaded certificate 
    service.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(
     "[PathToContainerFromStep7].p12", 
     "[YourPasswordFromStep8]"); 
    // Create authenticate request object 
    Apple.authenticateRequestType auth = new Apple.authenticateRequestType() 
    { 
     languageCode = "en", 
     userId = "[YourAppleServiceAccountNumber]", 
     userTimeZone = "[YourTimeZone]", 
     serviceAccountNo = "[YourSoldToNumber]" 
    }; 
    // Authenticate to Apple GSX 
    Apple.authenticateResponseType session = service.Authenticate(auth); 
    // Assign your new session id object 
    userSessionId = new Apple.gsxUserSessionType() { userSessionId = session.userSessionId }; 
}