Java 使用web服务客户端调用.net中开发的web服务时获取空指针

Java 使用web服务客户端调用.net中开发的web服务时获取空指针,java,web-services,websphere,Java,Web Services,Websphere,我正在使用在.net中开发的web服务。 我的平台是ibmrad、websphere7和jax-rpc 我编写了调用服务的代码,使其低于空指针异常。 客户端代码: // String // endPoint="https://pilot.id3global.com/ID3gWS/ID3global.svc/Soap11_NoAuth"; // String endPoint="BasicHttpBinding_GlobalAuthenticateStub";

我正在使用在.net中开发的web服务。 我的平台是ibmrad、websphere7和jax-rpc

我编写了调用服务的代码,使其低于空指针异常。 客户端代码:

     // String
      // endPoint="https://pilot.id3global.com/ID3gWS/ID3global.svc/Soap11_NoAuth";

      // String endPoint="BasicHttpBinding_GlobalAuthenticateStub";
      // GlobalAuthentication globalAuth =new GlobalAuthentication();

      Long l = new Long("0");
      // globalAuth.setProfileID("4a6eaf41-f9a9-44f0-9700-81aa43004dab");
      // globalAuth.setProfileVersion(l);

      GlobalProfileIDVersion profileIDVersion = new GlobalProfileIDVersion();

      profileIDVersion.setID("4a6eaf41-f9a9-44f0-9700-81aa43004dab");
      profileIDVersion.setVersion(l);

      GlobalInputData iInputData = new GlobalInputData();

      GlobalPersonal personal = new GlobalPersonal();
      GlobalPersonalDetails personalDetails = new GlobalPersonalDetails();
      personalDetails.setForename("Raymond");

      personalDetails.setSurname("Smith");
      personalDetails.setDOBDay(01);
      personalDetails.setDOBMonth(11);
      personalDetails.setDOBYear(1951);
      personalDetails.setGender(GlobalGender.Male);

      personal.setPersonalDetails(personalDetails);

      GlobalAddresses globalAddress = new GlobalAddresses();
      GlobalAddress globalAdres = new GlobalAddress();
      globalAdres.setPremise("3");
      // iInputData.Addresses.CurrentAddress.Building = "";
      // THis is commented out as I am just sending through a Building Number in
      // Premise whereas this is used for Building Names
      // iInputData.Addresses.CurrentAddress.SubBuilding = "";
      // This is commented out as no Flat/Apartment is being sent
      globalAdres.setStreet("High Street");
      globalAdres.setCity("Westbury");
      globalAdres.setZipPostcode("BA13 3BN");
      globalAdres.setCountry("United Kingdom");
      globalAddress.setCurrentAddress(globalAdres);
      GlobalIdentityDocuments identityDocuments = new GlobalIdentityDocuments();
      GlobalInternationalPassport internationalPassport = new GlobalInternationalPassport();
      internationalPassport
            .setNumber("1234567897GBR4511012M1803035<<<<<<<<<<<<<<00");
      internationalPassport.setExpiryDay(03);
      internationalPassport.setExpiryMonth(03);
      internationalPassport.setExpiryYear(2018);
      internationalPassport.setCountryOfOrigin("United Kingdom");

      identityDocuments.setInternationalPassport(internationalPassport);

      // BasicHttpBinding_GlobalAuthenticateStub stub=new
      // BasicHttpBinding_GlobalAuthenticateStub("https://pilot.id3global.com/ID3gWS/ID3global.svc/Soap11_NoAuth","dfasdf");
      // IGlobalAuthenticate authenticate=proxy.getIGlobalAuthenticate();

      URL wsdlLocationURL = new URL(
            "https://pilot.id3global.com/ID3gWS/ID3global.svc?wsdl");
//      URL wsdlLocationURL = new URL("WEB-INF/wsdl/ID3global.wsdl");
      // QName qname = new QName("http://www.id3global.com/ID3gWS/2013/04",
      // "AuthenticateSP");
      // Final===> QName qname = new
      // QName("http://www.id3global.com/ID3gWS/2013/04", "ID3global");
      QName qname = new QName("http://www.id3global.com/ID3gWS/2013/04",
            "ID3global");

      Service service = Service.create(wsdlLocationURL, qname);
      QName portQName = new QName("http://www.id3global.com/ID3gWS/2013/04",
            "basicHttpBinding_GlobalAuthenticate");
      IGlobalAuthenticate proxy = service.getPort(portQName,
            IGlobalAuthenticate.class);

      /******************* UserName & Password ******************************/
      Map<String, Object> req_ctx = ((BindingProvider) proxy)
            .getRequestContext();
//      req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
//            "https://pilot.id3global.com/ID3gWS/ID3global.svc?wsdl");

      Map<String, List<String>> headers = new HashMap<String, List<String>>();
      headers.put("Username", Collections.singletonList("nreddy"));
      headers.put("Password", Collections.singletonList("password"));
      req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headers);

      iInputData
            .setAddressDocuments(new GlobalAddressDocuments());
      iInputData.setAddresses(new GlobalAddresses());
      iInputData
            .setBankingDetails(new GlobalBankingDetails());
      iInputData
            .setContactDetails(new GlobalContactDetails());
      iInputData.setEmployment(new GlobalEmployment());
      iInputData.setGlobalGeneric(new GlobalGeneric());
      iInputData.setIdentityDocuments(identityDocuments);
      iInputData.setImages(new GlobalImage[1]);
      iInputData.setLocation(new GlobalLocation());
      iInputData.setPersonal(personal);
      // GlobalResultData response = null;
      try
      {
         GlobalResultData response = proxy.authenticateSP(profileIDVersion,
               "Example12345", iInputData);

         // System.out.println("out responce after the proxycall"+response.getBandText().toString());

      }
      catch ( RemoteException e )
      {
         e.printStackTrace();
      }
      catch ( Exception e )
      {
         e.printStackTrace();
      }

      return "";
我完全被这件事缠住了,任何帮助都将不胜感激

谢谢,
Naren

您可能创建了错误的服务

首先,您必须创建服务:

final Constructor<S> serviceConstructor = serviceClass.getConstructor(URL.class, QName.class);
serviceConstructor.newInstance(**null**, new QName(SERVICES_NAMESPACE, serviceName));

你的问题的答案在这里已经不是一个有用的评论。NPE位于(OP)第三方Web服务库中。
final Constructor<S> serviceConstructor = serviceClass.getConstructor(URL.class, QName.class);
serviceConstructor.newInstance(**null**, new QName(SERVICES_NAMESPACE, serviceName));
String endpointAddress = “http://.....”;
            ((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
            LOG.trace("Endpoint address is \"{}\".", endpointAddress);