2010-06-14 102 views
2

所以我一直在努力解決這個問題,奇怪的是當我運行一臺機器時,我得到了一個沒有描述的通用Axis故障,但現在在另一臺機器上我收到了一條不同的錯誤消息,但我仍然卡住了。基本上,我只是試圖做我認爲通過Web服務調用在Microsoft Dynamics CRM 4.0中創建新事件的相當簡單的任務。無法使用Java和Axis2在Dynamics CRM中創建新事件

我開始時從http://hostname/MSCrmServices/2007/CrmService.asmx下載XML並使用Axis2從它生成代碼。無論如何,這是我的計劃,任何幫助都將不勝感激,因爲我一直堅持這種方式的時間比我想象的要長,我真的沒有想法。

public class TestCRM { 

    private static String endpointURL = "http://theHost/MSCrmServices/2007/CrmService.asmx"; 
    private static String userName = "myUserNameHere"; 
    private static String password = "myPasswordHere"; 
    private static String host = "theHostname"; 
    private static int port = 80; 
    private static String domain = "theDomain"; 
    private static String orgName = "theOrganization"; 

    public static void main(String[] args) { 

     CrmServiceStub stub; 
     try { 
      stub = new CrmServiceStub(endpointURL); 
      setOptions(stub._getServiceClient().getOptions()); 

      RetrieveMultipleDocument rmd = RetrieveMultipleDocument.Factory.newInstance(); 
      com.microsoft.schemas.crm._2007.webservices.RetrieveMultipleDocument.RetrieveMultiple rm = com.microsoft.schemas.crm._2007.webservices.RetrieveMultipleDocument.RetrieveMultiple.Factory.newInstance(); 

      QueryExpression query = QueryExpression.Factory.newInstance(); 
      query.setColumnSet(AllColumns.Factory.newInstance()); 
      query.setEntityName(EntityName.INCIDENT.toString());  

      rm.setQuery(query); 
      rmd.setRetrieveMultiple(rm); 

      TargetCreateIncident tinc = TargetCreateIncident.Factory.newInstance(); 
      Incident inc = tinc.addNewIncident(); 
      inc.setDescription("This is a test of ticket creation through a web services call."); 

      CreateDocument cd = CreateDocument.Factory.newInstance(); 
      Create create = Create.Factory.newInstance(); 
      create.setEntity(inc); 

      cd.setCreate(create); 

      Incident test = (Incident)cd.getCreate().getEntity(); 

      CrmAuthenticationTokenDocument catd = CrmAuthenticationTokenDocument.Factory.newInstance(); 
      CrmAuthenticationToken token = CrmAuthenticationToken.Factory.newInstance(); 
      token.setAuthenticationType(0);  
      token.setOrganizationName(orgName); 
      catd.setCrmAuthenticationToken(token);   

      //The two printlns below spit back XML that looks okay to me? 
      System.out.println(cd); 
      System.out.println(catd); 
      /* stuff that doesn't work */ 
      CreateResponseDocument crd = stub.create(cd, catd, null, null); //this line throws the error 
      CreateResponse cr = crd.getCreateResponse(); 
      System.out.println("create result: " + cr.getCreateResult()); 
      /* End stuff that doesn't work */ 

      System.out.println(); 
      System.out.println(); 
      System.out.println(); 
      boolean fetchNext = true; 
      while(fetchNext){ 
       RetrieveMultipleResponseDocument rmrd = stub.retrieveMultiple(rmd, catd, null, null); 
       //This retrieve using the CRMAuthenticationToken catd works just fine 

       RetrieveMultipleResponse rmr = rmrd.getRetrieveMultipleResponse(); 
       BusinessEntityCollection bec = rmr.getRetrieveMultipleResult(); 

       String pagingCookie = bec.getPagingCookie(); 
       fetchNext = bec.getMoreRecords(); 

       ArrayOfBusinessEntity aobe = bec.getBusinessEntities(); 
       BusinessEntity[] myEntitiesAtLast = aobe.getBusinessEntityArray(); 

       for(int i=0; i<myEntitiesAtLast.length; i++){ 
        //cast to whatever you asked for... 
        Incident myEntity = (Incident) myEntitiesAtLast[i]; 
        System.out.println("["+(i+1)+"]: " + myEntity); 
       } 
      } 
     } 
     catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    private static void setOptions(Options options){ 
     HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); 

     List authSchemes = new ArrayList(); 
     authSchemes.add(HttpTransportProperties.Authenticator.NTLM); 
     auth.setAuthSchemes(authSchemes); 

     auth.setUsername(userName); 
     auth.setPassword(password); 
     auth.setHost(host); 
     auth.setPort(port); 
     auth.setDomain(domain); 
     auth.setPreemptiveAuthentication(false); 
     options.setProperty(HTTPConstants.AUTHENTICATE, auth); 
     options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, "true"); 
    } 
} 

而且,這裏的錯誤消息我收到:

org.apache.axis2.AxisFault: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'S' (code 83) in prolog; expected '<' 
at [row,col {unknown-source}]: [1,1] 
    at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430) 
    at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:123) 
    at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:67) 
    at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:354) 
    at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417) 
    at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229) 
    at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165) 
    at com.spanlink.crm.dynamics4.webservice.CrmServiceStub.create(CrmServiceStub.java:618) 
    at com.spanlink.crm.dynamics4.runtime.TestCRM.main(TestCRM.java:82) 
Caused by: org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'S' (code 83) in prolog; expected '<' 
at [row,col {unknown-source}]: [1,1] 
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:260) 
    at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:161) 
    at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:110) 
    at org.apache.axis2.builder.BuilderUtil.getSOAPBuilder(BuilderUtil.java:682) 
    at org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:215) 
    at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:145) 
    at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:108) 
    ... 7 more 
Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'S' (code 83) in prolog; expected '<' 
at [row,col {unknown-source}]: [1,1] 
    at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:623) 
    at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2047) 
    at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1069) 
    at javax.xml.stream.util.StreamReaderDelegate.next(StreamReaderDelegate.java:60) 
    at org.apache.axiom.om.impl.builder.SafeXMLStreamReader.next(SafeXMLStreamReader.java:183) 
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.parserNext(StAXOMBuilder.java:597) 
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:172) 
    ... 13 more 

編輯:嗯,我想,也許我上的東西。我使用wireshark來查看發生了什麼,看起來'S'來自服務器響應。嗅探流量,看起來問題是,「服務器無法處理請求。」 - >調用目標引發了異常--->您應指定父級聯繫人或帳戶。\ r \ ñ「

我會離開這個懸而未決,因爲我在技術上還沒有它的工作,但至少我知道現在發生了什麼。

回答

0

我能夠得到它的工作,只需要添加一個父帳戶。

+0

有你實現MS CRM。在遵循http://javamscrm.codeplex.com/提供的參考資料時,我遇到了一個問題。你可以請幫助實施crm通過java – 2012-11-29 11:10:12

0

我很高興你有這個工作。當CRM引發異常時,首先要檢查CRM跟蹤日誌。客戶關係管理提供了一個很好的描述出了什麼問題這有助於大幅縮小調查範圍。

上在服務器上啓用跟蹤更多信息: http://support.microsoft.com/kb/907490

相關問題